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/insetnewline.h"
37 extern string bibitemWidest(Buffer const *);
39 using namespace lyx::support;
42 //using lyx::layout_type;
47 void breakParagraph(BufferParams const & bparams,
48 ParagraphList & paragraphs,
49 ParagraphList::iterator par,
53 // create a new paragraph, and insert into the list
54 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
57 // without doing that we get a crash when typing <Return> at the
59 tmp->layout(bparams.getLyXTextClass().defaultLayout());
60 // remember to set the inset_owner
61 tmp->setInsetOwner(par->inInset());
63 if (bparams.tracking_changes)
66 // this is an idea for a more userfriendly layout handling, I will
67 // see what the users say
69 // layout stays the same with latex-environments
71 tmp->layout(par->layout());
72 tmp->setLabelWidthString(par->params().labelWidthString());
75 bool const isempty = (par->allowEmpty() && par->empty());
77 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
78 tmp->layout(par->layout());
79 tmp->params().align(par->params().align());
80 tmp->setLabelWidthString(par->params().labelWidthString());
82 tmp->params().lineBottom(par->params().lineBottom());
83 par->params().lineBottom(false);
84 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
85 par->params().pagebreakBottom(false);
86 tmp->params().spaceBottom(par->params().spaceBottom());
87 par->params().spaceBottom(VSpace(VSpace::NONE));
89 tmp->params().depth(par->params().depth());
90 tmp->params().noindent(par->params().noindent());
92 // copy everything behind the break-position
93 // to the new paragraph
96 #warning this seems wrong
98 /* FIXME: if !keepempty, empty() == true, then we reach
99 * here with size() == 0. So pos_end becomes - 1. Why
100 * doesn't this cause problems ???
102 pos_type pos_end = par->size() - 1;
106 for (; i <= pos_end; ++i) {
107 Change::Type change(par->lookupChange(i));
108 par->cutIntoMinibuffer(bparams, i);
109 if (tmp->insertFromMinibuffer(j - pos)) {
110 tmp->setChange(j - pos, change);
114 for (i = pos_end; i >= pos; --i) {
122 tmp->params().lineTop(par->params().lineTop());
123 tmp->params().pagebreakTop(par->params().pagebreakTop());
124 tmp->params().spaceTop(par->params().spaceTop());
125 par->params().clear();
127 par->layout(bparams.getLyXTextClass().defaultLayout());
129 // layout stays the same with latex-environments
131 par->layout(tmp->layout());
132 par->setLabelWidthString(tmp->params().labelWidthString());
133 par->params().depth(tmp->params().depth());
136 // subtle, but needed to get empty pars working right
137 if (bparams.tracking_changes) {
140 } else if (!tmp->size()) {
147 void breakParagraphConservative(BufferParams const & bparams,
148 ParagraphList & paragraphs,
149 ParagraphList::iterator par,
152 // create a new paragraph
153 ParagraphList::iterator tmp = paragraphs.insert(boost::next(par),
155 tmp->makeSameLayout(*par);
157 // When can pos > size()?
158 // I guess pos == size() is possible.
159 if (par->size() > pos) {
160 // copy everything behind the break-position to the new
162 pos_type pos_end = par->size() - 1;
164 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
165 par->cutIntoMinibuffer(bparams, i);
166 if (tmp->insertFromMinibuffer(j - pos))
170 for (pos_type k = pos_end; k >= pos; --k) {
177 void mergeParagraph(BufferParams const & bparams,
178 ParagraphList & paragraphs,
179 ParagraphList::iterator par)
181 ParagraphList::iterator the_next = boost::next(par);
183 // first the DTP-stuff
184 par->params().lineBottom(the_next->params().lineBottom());
185 par->params().spaceBottom(the_next->params().spaceBottom());
186 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
188 pos_type pos_end = the_next->size() - 1;
189 pos_type pos_insert = par->size();
191 // ok, now copy the paragraph
192 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
193 the_next->cutIntoMinibuffer(bparams, i);
194 if (par->insertFromMinibuffer(pos_insert + j))
198 paragraphs.erase(the_next);
202 ParagraphList::iterator depthHook(ParagraphList::iterator pit,
203 ParagraphList const & plist,
204 Paragraph::depth_type depth)
206 ParagraphList::iterator newpit = pit;
207 ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
212 while (newpit != beg && newpit->getDepth() > depth) {
216 if (newpit->getDepth() > depth)
223 ParagraphList::iterator outerHook(ParagraphList::iterator pit,
224 ParagraphList const & plist)
226 if (!pit->getDepth())
227 return const_cast<ParagraphList&>(plist).end();
228 return depthHook(pit, plist,
229 Paragraph::depth_type(pit->getDepth() - 1));
233 bool isFirstInSequence(ParagraphList::iterator pit,
234 ParagraphList const & plist)
236 ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
238 || dhook->layout() != pit->layout()
239 || dhook->getDepth() != pit->getDepth());
243 int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
245 ParagraphList::iterator pit = p;
246 Paragraph::depth_type par_depth = p->getDepth();
247 while (pit != const_cast<ParagraphList&>(plist).end()) {
248 LyXLayout_ptr const & layout = pit->layout();
249 int const endlabeltype = layout->endlabeltype;
251 if (endlabeltype != END_LABEL_NO_LABEL) {
252 if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
255 Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
256 if (par_depth > next_depth ||
257 (par_depth == next_depth &&
258 layout != boost::next(p)->layout()))
264 pit = outerHook(pit, plist);
265 if (pit != const_cast<ParagraphList&>(plist).end())
266 par_depth = pit->getDepth();
268 return END_LABEL_NO_LABEL;
274 ParagraphList::iterator
275 TeXEnvironment(Buffer const * buf,
276 ParagraphList const & paragraphs,
277 ParagraphList::iterator pit,
278 ostream & os, TexRow & texrow,
279 LatexRunParams const & runparams);
281 ParagraphList::iterator
282 TeXOnePar(Buffer const * buf,
283 ParagraphList const & paragraphs,
284 ParagraphList::iterator pit,
285 ostream & os, TexRow & texrow,
286 LatexRunParams const & runparams,
287 string const & everypar = string());
290 ParagraphList::iterator
291 TeXDeeper(Buffer const * buf,
292 ParagraphList const & paragraphs,
293 ParagraphList::iterator pit,
294 ostream & os, TexRow & texrow,
295 LatexRunParams const & runparams)
297 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
298 ParagraphList::iterator par = pit;
300 while (par != const_cast<ParagraphList&>(paragraphs).end() &&
301 par->params().depth() == pit->params().depth()) {
302 if (par->layout()->isEnvironment()) {
303 par = TeXEnvironment(buf, paragraphs, par,
304 os, texrow, runparams);
306 par = TeXOnePar(buf, paragraphs, par,
307 os, texrow, runparams);
310 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
316 ParagraphList::iterator
317 TeXEnvironment(Buffer const * buf,
318 ParagraphList const & paragraphs,
319 ParagraphList::iterator pit,
320 ostream & os, TexRow & texrow,
321 LatexRunParams const & runparams)
323 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
325 BufferParams const & bparams = buf->params;
327 LyXLayout_ptr const & style = pit->layout();
329 Language const * language = pit->getParLanguage(bparams);
330 Language const * doc_language = bparams.language;
331 Language const * previous_language =
332 (pit != const_cast<ParagraphList&>(paragraphs).begin())
333 ? boost::prior(pit)->getParLanguage(bparams)
335 if (language->babel() != previous_language->babel()) {
337 if (!lyxrc.language_command_end.empty() &&
338 previous_language->babel() != doc_language->babel()) {
339 os << subst(lyxrc.language_command_end, "$$lang",
340 previous_language->babel())
345 if (lyxrc.language_command_end.empty() ||
346 language->babel() != doc_language->babel()) {
347 os << subst(lyxrc.language_command_begin, "$$lang",
354 bool leftindent_open = false;
355 if (!pit->params().leftIndent().zero()) {
356 os << "\\begin{LyXParagraphLeftIndent}{" <<
357 pit->params().leftIndent().asLatexString() << "}\n";
359 leftindent_open = true;
362 if (style->isEnvironment()) {
363 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
364 os << "\\begin{" << style->latexname() << "}{"
365 << pit->params().labelWidthString() << "}\n";
366 } else if (style->labeltype == LABEL_BIBLIO) {
368 os << "\\begin{" << style->latexname() << "}{"
369 << bibitemWidest(buf)
371 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
372 os << "\\begin{" << style->latexname() << '}'
373 << style->latexparam() << '\n';
375 os << "\\begin{" << style->latexname() << '}'
376 << style->latexparam() << '\n';
379 ParagraphList::iterator par = pit;
381 par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
383 if (par != const_cast<ParagraphList&>(paragraphs).end() && par->params().depth() > pit->params().depth()) {
384 if (par->layout()->isParagraph()) {
387 // How to handle this? (Lgb)
388 //&& !suffixIs(os, "\n\n")
390 // There should be at least one '\n' already
391 // but we need there to be two for Standard
392 // paragraphs that are depth-increment'ed to be
393 // output correctly. However, tables can
394 // also be paragraphs so don't adjust them.
397 // Will it ever harm to have one '\n' too
398 // many? i.e. that we sometimes will have
399 // three in a row. (Lgb)
403 par = TeXDeeper(buf, paragraphs, par, os, texrow,
406 } while (par != const_cast<ParagraphList&>(paragraphs).end()
407 && par->layout() == pit->layout()
408 && par->params().depth() == pit->params().depth()
409 && par->params().leftIndent() == pit->params().leftIndent());
411 if (style->isEnvironment()) {
412 os << "\\end{" << style->latexname() << "}\n";
416 if (leftindent_open) {
417 os << "\\end{LyXParagraphLeftIndent}\n";
421 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
422 return par; // ale970302
426 InsetOptArg * optArgInset(Paragraph const & par)
429 InsetList::const_iterator it = par.insetlist.begin();
430 InsetList::const_iterator end = par.insetlist.end();
431 for (; it != end; ++it) {
432 InsetOld * ins = it->inset;
433 if (ins->lyxCode() == InsetOld::OPTARG_CODE) {
434 return static_cast<InsetOptArg *>(ins);
441 ParagraphList::iterator
442 TeXOnePar(Buffer const * buf,
443 ParagraphList const & paragraphs,
444 ParagraphList::iterator pit,
445 ostream & os, TexRow & texrow,
446 LatexRunParams const & runparams,
447 string const & everypar)
449 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '" << everypar
451 BufferParams const & bparams = buf->params;
453 InsetOld const * in = pit->inInset();
454 bool further_blank_line = false;
457 // well we have to check if we are in an inset with unlimited
458 // lenght (all in one row) if that is true then we don't allow
459 // any special options in the paragraph and also we don't allow
460 // any environment other then "Standard" to be valid!
461 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
462 style = pit->layout();
464 if (pit->params().startOfAppendix()) {
465 os << "\\appendix\n";
469 if (!pit->params().spacing().isDefault()
470 && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
471 os << pit->params().spacing().writeEnvirBegin() << '\n';
475 if (style->isCommand()) {
480 if (pit->params().pagebreakTop()) {
482 further_blank_line = true;
484 if (pit->params().spaceTop().kind() != VSpace::NONE) {
485 os << pit->params().spaceTop().asLatexCommand(bparams);
486 further_blank_line = true;
489 if (pit->params().lineTop()) {
491 << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize()
493 << "\\vspace{-1\\parskip}";
494 further_blank_line = true;
497 if (further_blank_line) {
502 style = bparams.getLyXTextClass().defaultLayout();
505 Language const * language = pit->getParLanguage(bparams);
506 Language const * doc_language = bparams.language;
507 Language const * previous_language =
508 (pit != const_cast<ParagraphList&>(paragraphs).begin())
509 ? boost::prior(pit)->getParLanguage(bparams)
512 if (language->babel() != previous_language->babel()
513 // check if we already put language command in TeXEnvironment()
514 && !(style->isEnvironment()
515 && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
516 (boost::prior(pit)->layout() != pit->layout() &&
517 boost::prior(pit)->getDepth() <= pit->getDepth())
518 || boost::prior(pit)->getDepth() < pit->getDepth())))
520 if (!lyxrc.language_command_end.empty() &&
521 previous_language->babel() != doc_language->babel())
523 os << subst(lyxrc.language_command_end, "$$lang",
524 previous_language->babel())
529 if (lyxrc.language_command_end.empty() ||
530 language->babel() != doc_language->babel())
532 os << subst(lyxrc.language_command_begin, "$$lang",
539 if (bparams.inputenc == "auto" &&
540 language->encoding() != previous_language->encoding()) {
541 os << "\\inputencoding{"
542 << language->encoding()->LatexName()
547 switch (style->latextype) {
549 os << '\\' << style->latexname();
551 // Separate handling of optional argument inset.
552 if (style->optionalargs == 1) {
553 InsetOptArg * it = optArgInset(*pit);
555 it->latexOptional(buf, os, runparams);
558 os << style->latexparam();
560 case LATEX_ITEM_ENVIRONMENT:
561 case LATEX_LIST_ENVIRONMENT:
564 case LATEX_BIB_ENVIRONMENT:
565 // ignore this, the inset will write itself
572 bool need_par = pit->simpleTeXOnePar(buf, bparams,
573 outerFont(pit, paragraphs),
574 os, texrow, runparams);
576 // Make sure that \\par is done with the font of the last
577 // character if this has another size as the default.
578 // This is necessary because LaTeX (and LyX on the screen)
579 // calculates the space between the baselines according
580 // to this font. (Matthias)
582 // Is this really needed ? (Dekel)
583 // We do not need to use to change the font for the last paragraph
585 LyXFont const outerfont(outerFont(pit, paragraphs));
589 ? pit->getLayoutFont(bparams, outerfont)
590 : pit->getFont(bparams, pit->size() - 1, outerfont));
592 bool is_command = style->isCommand();
594 if (style->resfont.size() != font.size()
595 && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
599 os << "\\" << font.latexSize() << " \\par}";
600 } else if (need_par) {
602 } else if (is_command)
605 switch (style->latextype) {
606 case LATEX_ITEM_ENVIRONMENT:
607 case LATEX_LIST_ENVIRONMENT:
608 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
609 && (pit->params().depth() < boost::next(pit)->params().depth())) {
614 case LATEX_ENVIRONMENT: {
615 // if its the last paragraph of the current environment
616 // skip it otherwise fall through
617 ParagraphList::iterator next = boost::next(pit);
619 if (next != const_cast<ParagraphList&>(paragraphs).end()
620 && (next->layout() != pit->layout()
621 || next->params().depth() != pit->params().depth()))
625 // fall through possible
627 // we don't need it for the last paragraph!!!
628 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
634 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
635 further_blank_line = false;
636 if (pit->params().lineBottom()) {
637 os << "\\lyxline{\\" << font.latexSize() << '}';
638 further_blank_line = true;
641 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
642 os << pit->params().spaceBottom().asLatexCommand(bparams);
643 further_blank_line = true;
646 if (pit->params().pagebreakBottom()) {
648 further_blank_line = true;
651 if (further_blank_line) {
656 if (!pit->params().spacing().isDefault()
657 && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
658 os << pit->params().spacing().writeEnvirEnd() << '\n';
663 // we don't need it for the last paragraph!!!
664 if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
668 // Since \selectlanguage write the language to the aux file,
669 // we need to reset the language at the end of footnote or
672 if (language->babel() != doc_language->babel()) {
673 if (lyxrc.language_command_end.empty())
674 os << subst(lyxrc.language_command_begin,
676 doc_language->babel())
679 os << subst(lyxrc.language_command_end,
687 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
695 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
697 void latexParagraphs(Buffer const * buf,
698 ParagraphList const & paragraphs,
701 LatexRunParams const & runparams,
702 string const & everypar)
704 bool was_title = false;
705 bool already_title = false;
706 LyXTextClass const & tclass = buf->params.getLyXTextClass();
707 ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
708 ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
711 while (par != endpar) {
712 InsetOld * in = par->inInset();
713 // well we have to check if we are in an inset with unlimited
714 // length (all in one row) if that is true then we don't allow
715 // any special options in the paragraph and also we don't allow
716 // any environment other then "Standard" to be valid!
717 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
718 LyXLayout_ptr const & layout = par->layout();
720 if (layout->intitle) {
722 lyxerr <<"Error in latexParagraphs: You"
723 " should not mix title layouts"
724 " with normal ones." << endl;
725 } else if (!was_title) {
727 if (tclass.titletype() == TITLE_ENVIRONMENT) {
729 << tclass.titlename()
734 } else if (was_title && !already_title) {
735 if (tclass.titletype() == TITLE_ENVIRONMENT) {
736 os << "\\end{" << tclass.titlename()
740 os << "\\" << tclass.titlename()
744 already_title = true;
748 if (layout->is_environment) {
749 par = TeXOnePar(buf, paragraphs, par, os, texrow,
750 runparams, everypar);
751 } else if (layout->isEnvironment() ||
752 !par->params().leftIndent().zero())
754 par = TeXEnvironment(buf, paragraphs, par, os,
757 par = TeXOnePar(buf, paragraphs, par, os, texrow,
758 runparams, everypar);
761 par = TeXOnePar(buf, paragraphs, par, os, texrow,
762 runparams, everypar);
765 // It might be that we only have a title in this document
766 if (was_title && !already_title) {
767 if (tclass.titletype() == TITLE_ENVIRONMENT) {
768 os << "\\end{" << tclass.titlename()
772 os << "\\" << tclass.titlename()
782 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
785 static Change change;
787 BufferParams const & bp = buf.params;
789 if (token[0] != '\\') {
790 string::const_iterator cit = token.begin();
791 for (; cit != token.end(); ++cit) {
792 par.insertChar(par.size(), (*cit), font, change);
794 } else if (token == "\\layout") {
796 string layoutname = lex.getString();
798 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
801 LyXTextClass const & tclass = bp.getLyXTextClass();
803 if (layoutname.empty()) {
804 layoutname = tclass.defaultLayoutName();
807 bool hasLayout = tclass.hasLayout(layoutname);
810 lyxerr << "Layout '" << layoutname << "' does not"
811 << " exist in textclass '" << tclass.name()
813 lyxerr << "Trying to use default layout instead."
815 layoutname = tclass.defaultLayoutName();
819 // The is the compability reading of layout caption.
820 if (compare_ascii_no_case(layoutname, "caption") == 0) {
821 // We expect that the par we are now working on is
822 // really inside a InsetText inside a InsetFloat.
823 // We also know that captions can only be
824 // one paragraph. (Lgb)
826 // We should now read until the next "\layout"
828 // This is probably not good enough, what if the
829 // caption is the last par in the document (Lgb)
830 istream & ist = lex.getStream();
836 if (prefixIs(line, "\\layout")) {
840 if (prefixIs(line, "\\begin_inset"))
842 if (prefixIs(line, "\\end_inset")) {
854 // Now we should have the whole layout in ss
855 // we should now be able to give this to the
857 ss << "\\end_inset\n";
859 // This seems like a bug in stringstream.
860 // We really should be able to use ss
862 istringstream is(ss.str());
864 tmplex.setStream(is);
865 InsetOld * inset = new InsetCaption;
866 inset->Read(this, tmplex);
867 par.insertInset(pos, inset, font);
871 par.layout(bp.getLyXTextClass()[layoutname]);
873 // Test whether the layout is obsolete.
874 LyXLayout_ptr const & layout = par.layout();
875 if (!layout->obsoleted_by().empty())
876 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
878 par.params().read(lex);
883 } else if (token == "\\end_inset") {
884 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
885 << "Missing \\begin_inset?.\n";
886 // Simply ignore this. The insets do not have
888 // But insets should read it, it is a part of
889 // the inset isn't it? Lgb.
890 } else if (token == "\\begin_inset") {
891 InsetOld * i = readInset(lex, buf);
892 par.insertInset(par.size(), i, font, change);
893 } else if (token == "\\family") {
895 font.setLyXFamily(lex.getString());
896 } else if (token == "\\series") {
898 font.setLyXSeries(lex.getString());
899 } else if (token == "\\shape") {
901 font.setLyXShape(lex.getString());
902 } else if (token == "\\size") {
904 font.setLyXSize(lex.getString());
905 } else if (token == "\\lang") {
907 string const tok = lex.getString();
908 Language const * lang = languages.getLanguage(tok);
910 font.setLanguage(lang);
912 font.setLanguage(bp.language);
913 lex.printError("Unknown language `$$Token'");
915 } else if (token == "\\numeric") {
917 font.setNumber(font.setLyXMisc(lex.getString()));
918 } else if (token == "\\emph") {
920 font.setEmph(font.setLyXMisc(lex.getString()));
921 } else if (token == "\\bar") {
923 string const tok = lex.getString();
926 font.setUnderbar(LyXFont::ON);
927 else if (tok == "no")
928 font.setUnderbar(LyXFont::OFF);
929 else if (tok == "default")
930 font.setUnderbar(LyXFont::INHERIT);
932 lex.printError("Unknown bar font flag "
934 } else if (token == "\\noun") {
936 font.setNoun(font.setLyXMisc(lex.getString()));
937 } else if (token == "\\color") {
939 font.setLyXColor(lex.getString());
940 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
942 // Insets don't make sense in a free-spacing context! ---Kayvan
943 if (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!");
958 InsetOld * inset = 0;
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 InsetOld * 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 InsetOld * inset = new InsetNewline;
974 inset->read(&buf, lex);
975 par.insertInset(par.size(), inset, font, change);
976 } else if (token == "\\LyXTable") {
977 InsetOld * 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());
1012 buf.error(ErrorItem(_("Unknown token"), s,
1013 par.id(), 0, par.size()));
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());