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 = const_cast<ParagraphList&>(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())
226 return const_cast<ParagraphList&>(plist).end();
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 != const_cast<ParagraphList&>(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) == const_cast<ParagraphList&>(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 != const_cast<ParagraphList&>(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 != const_cast<ParagraphList&>(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 != const_cast<ParagraphList&>(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 != const_cast<ParagraphList&>(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 != const_cast<ParagraphList&>(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::const_iterator it = par.insetlist.begin();
429 InsetList::const_iterator end = par.insetlist.end();
430 for (; it != end; ++it) {
431 Inset * ins = it->inset;
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 == const_cast<ParagraphList&>(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 != const_cast<ParagraphList&>(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 == const_cast<ParagraphList&>(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) != const_cast<ParagraphList&>(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) != const_cast<ParagraphList&>(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 ParagraphList::iterator next = boost::next(pit);
618 if (next != const_cast<ParagraphList&>(paragraphs).end()
619 && (next->layout() != pit->layout()
620 || next->params().depth() != pit->params().depth()))
624 // fall through possible
626 // we don't need it for the last paragraph!!!
627 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
633 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
634 further_blank_line = false;
635 if (pit->params().lineBottom()) {
636 os << "\\lyxline{\\" << font.latexSize() << '}';
637 further_blank_line = true;
640 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
641 os << pit->params().spaceBottom().asLatexCommand(bparams);
642 further_blank_line = true;
645 if (pit->params().pagebreakBottom()) {
647 further_blank_line = true;
650 if (further_blank_line) {
655 if (!pit->params().spacing().isDefault()
656 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
657 os << pit->params().spacing().writeEnvirEnd() << '\n';
662 // we don't need it for the last paragraph!!!
663 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
667 // Since \selectlanguage write the language to the aux file,
668 // we need to reset the language at the end of footnote or
671 if (language->babel() != doc_language->babel()) {
672 if (lyxrc.language_command_end.empty())
673 os << subst(lyxrc.language_command_begin,
675 doc_language->babel())
678 os << subst(lyxrc.language_command_end,
686 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
694 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
696 void latexParagraphs(Buffer const * buf,
697 ParagraphList const & paragraphs,
700 LatexRunParams const & runparams,
701 string const & everypar)
703 bool was_title = false;
704 bool already_title = false;
705 LyXTextClass const & tclass = buf->params.getLyXTextClass();
706 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
707 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
710 while (par != endpar) {
711 Inset * in = par->inInset();
712 // well we have to check if we are in an inset with unlimited
713 // length (all in one row) if that is true then we don't allow
714 // any special options in the paragraph and also we don't allow
715 // any environment other then "Standard" to be valid!
716 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
717 LyXLayout_ptr const & layout = par->layout();
719 if (layout->intitle) {
721 lyxerr <<"Error in latexParagraphs: You"
722 " should not mix title layouts"
723 " with normal ones." << endl;
724 } else if (!was_title) {
726 if (tclass.titletype() == TITLE_ENVIRONMENT) {
728 << tclass.titlename()
733 } else if (was_title && !already_title) {
734 if (tclass.titletype() == TITLE_ENVIRONMENT) {
735 os << "\\end{" << tclass.titlename()
739 os << "\\" << tclass.titlename()
743 already_title = true;
747 if (layout->is_environment) {
748 par = TeXOnePar(buf, paragraphs, par, os, texrow,
749 runparams, everypar);
750 } else if (layout->isEnvironment() ||
751 !par->params().leftIndent().zero())
753 par = TeXEnvironment(buf, paragraphs, par, os,
756 par = TeXOnePar(buf, paragraphs, par, os, texrow,
757 runparams, everypar);
760 par = TeXOnePar(buf, paragraphs, par, os, texrow,
761 runparams, everypar);
764 // It might be that we only have a title in this document
765 if (was_title && !already_title) {
766 if (tclass.titletype() == TITLE_ENVIRONMENT) {
767 os << "\\end{" << tclass.titlename()
771 os << "\\" << tclass.titlename()
781 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
784 static Change change;
786 BufferParams const & bp = buf.params;
788 if (token[0] != '\\') {
789 string::const_iterator cit = token.begin();
790 for (; cit != token.end(); ++cit) {
791 par.insertChar(par.size(), (*cit), font, change);
793 } else if (token == "\\layout") {
795 string layoutname = lex.getString();
797 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
800 LyXTextClass const & tclass = bp.getLyXTextClass();
802 if (layoutname.empty()) {
803 layoutname = tclass.defaultLayoutName();
806 bool hasLayout = tclass.hasLayout(layoutname);
809 lyxerr << "Layout '" << layoutname << "' does not"
810 << " exist in textclass '" << tclass.name()
812 lyxerr << "Trying to use default layout instead."
814 layoutname = tclass.defaultLayoutName();
818 // The is the compability reading of layout caption.
819 if (compare_ascii_no_case(layoutname, "caption") == 0) {
820 // We expect that the par we are now working on is
821 // really inside a InsetText inside a InsetFloat.
822 // We also know that captions can only be
823 // one paragraph. (Lgb)
825 // We should now read until the next "\layout"
827 // This is probably not good enough, what if the
828 // caption is the last par in the document (Lgb)
829 istream & ist = lex.getStream();
835 if (prefixIs(line, "\\layout")) {
839 if (prefixIs(line, "\\begin_inset"))
841 if (prefixIs(line, "\\end_inset")) {
853 // Now we should have the whole layout in ss
854 // we should now be able to give this to the
856 ss << "\\end_inset\n";
858 // This seems like a bug in stringstream.
859 // We really should be able to use ss
861 istringstream is(ss.str());
863 tmplex.setStream(is);
864 Inset * inset = new InsetCaption;
865 inset->Read(this, tmplex);
866 par.insertInset(pos, inset, font);
870 par.layout(bp.getLyXTextClass()[layoutname]);
872 // Test whether the layout is obsolete.
873 LyXLayout_ptr const & layout = par.layout();
874 if (!layout->obsoleted_by().empty())
875 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
877 par.params().read(lex);
882 } else if (token == "\\end_inset") {
883 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
884 << "Missing \\begin_inset?.\n";
885 // Simply ignore this. The insets do not have
887 // But insets should read it, it is a part of
888 // the inset isn't it? Lgb.
889 } else if (token == "\\begin_inset") {
890 Inset * i = readInset(lex, buf);
891 par.insertInset(par.size(), i, font, change);
892 } else if (token == "\\family") {
894 font.setLyXFamily(lex.getString());
895 } else if (token == "\\series") {
897 font.setLyXSeries(lex.getString());
898 } else if (token == "\\shape") {
900 font.setLyXShape(lex.getString());
901 } else if (token == "\\size") {
903 font.setLyXSize(lex.getString());
904 } else if (token == "\\lang") {
906 string const tok = lex.getString();
907 Language const * lang = languages.getLanguage(tok);
909 font.setLanguage(lang);
911 font.setLanguage(bp.language);
912 lex.printError("Unknown language `$$Token'");
914 } else if (token == "\\numeric") {
916 font.setNumber(font.setLyXMisc(lex.getString()));
917 } else if (token == "\\emph") {
919 font.setEmph(font.setLyXMisc(lex.getString()));
920 } else if (token == "\\bar") {
922 string const tok = lex.getString();
925 font.setUnderbar(LyXFont::ON);
926 else if (tok == "no")
927 font.setUnderbar(LyXFont::OFF);
928 else if (tok == "default")
929 font.setUnderbar(LyXFont::INHERIT);
931 lex.printError("Unknown bar font flag "
933 } else if (token == "\\noun") {
935 font.setNoun(font.setLyXMisc(lex.getString()));
936 } else if (token == "\\color") {
938 font.setLyXColor(lex.getString());
939 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
940 LyXLayout_ptr const & layout = par.layout();
942 // Insets don't make sense in a free-spacing context! ---Kayvan
943 if (layout->free_spacing || par.isFreeSpacing()) {
944 if (token == "\\InsetSpace")
945 par.insertChar(par.size(), ' ', font, change);
946 else if (lex.isOK()) {
948 string const next_token = lex.getString();
949 if (next_token == "\\-")
950 par.insertChar(par.size(), '-', font, change);
952 lex.printError("Token `$$Token' "
954 "paragraph layout!");
959 if (token == "\\SpecialChar" )
960 inset = new InsetSpecialChar;
962 inset = new InsetSpace;
963 inset->read(&buf, lex);
964 par.insertInset(par.size(), inset, font, change);
966 } else if (token == "\\i") {
967 Inset * inset = new InsetLatexAccent;
968 inset->read(&buf, lex);
969 par.insertInset(par.size(), inset, font, change);
970 } else if (token == "\\backslash") {
971 par.insertChar(par.size(), '\\', font, change);
972 } else if (token == "\\newline") {
973 Inset * inset = new InsetNewline;
974 inset->read(&buf, lex);
975 par.insertInset(par.size(), inset, font, change);
976 } else if (token == "\\LyXTable") {
977 Inset * inset = new InsetTabular(buf);
978 inset->read(&buf, lex);
979 par.insertInset(par.size(), inset, font, change);
980 } else if (token == "\\bibitem") {
981 InsetCommandParams p("bibitem", "dummy");
982 InsetBibitem * inset = new InsetBibitem(p);
983 inset->read(&buf, lex);
984 par.insertInset(par.size(), inset, font, change);
985 } else if (token == "\\hfill") {
986 par.insertInset(par.size(), new InsetHFill(), font, change);
987 } else if (token == "\\change_unchanged") {
988 // Hack ! Needed for empty paragraphs :/
989 // FIXME: is it still ??
992 change = Change(Change::UNCHANGED);
993 } else if (token == "\\change_inserted") {
995 istringstream is(STRCONV(lex.getString()));
999 change = Change(Change::INSERTED, bp.author_map[aid], ct);
1000 } else if (token == "\\change_deleted") {
1002 istringstream is(STRCONV(lex.getString()));
1006 change = Change(Change::DELETED, bp.author_map[aid], ct);
1009 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
1010 token, lex.getString());
1011 // we can do this here this way because we're actually reading
1012 // the buffer and don't care about LyXText right now.
1013 par.insertInset(par.size(), new InsetError(s), font);
1022 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
1027 string token = lex.getString();
1029 while (lex.isOK()) {
1031 unknown += readParToken(buf, par, lex, token);
1034 token = lex.getString();
1039 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1040 << token << '\'' << endl;
1042 // reached the next paragraph. FIXME: really we should
1043 // change the file format to indicate the end of a par
1044 // clearly, but for now, this hack will do
1045 if (token == "\\layout" || token == "\\the_end"
1046 || token == "\\end_inset" || token == "\\begin_deeper"
1047 || token == "\\end_deeper") {
1048 lex.pushToken(token);
1057 LyXFont const outerFont(ParagraphList::iterator pit,
1058 ParagraphList const & plist)
1060 Paragraph::depth_type par_depth = pit->getDepth();
1061 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1063 // Resolve against environment font information
1064 while (pit != const_cast<ParagraphList&>(plist).end() &&
1065 par_depth && !tmpfont.resolved()) {
1066 pit = outerHook(pit, plist);
1067 if (pit != const_cast<ParagraphList&>(plist).end()) {
1068 tmpfont.realize(pit->layout()->font);
1069 par_depth = pit->getDepth();
1077 LyXFont const realizeFont(LyXFont const & font,
1078 BufferParams const & params)
1080 LyXTextClass const & tclass = params.getLyXTextClass();
1081 LyXFont tmpfont(font);
1082 tmpfont.realize(tclass.defaultfont());