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"
24 #include "support/BoostFormat.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 > Last()?
155 // I guess pos == Last() 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 Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth)
201 Paragraph * newpar = par;
204 newpar = newpar->previous();
205 } while (newpar && newpar->getDepth() > depth);
208 if (par->previous() || par->getDepth())
209 lyxerr << "ERROR (Paragraph::DepthHook): "
218 Paragraph * outerHook(Paragraph * par)
220 if (!par->getDepth())
222 return depthHook(par, Paragraph::depth_type(par->getDepth() - 1));
226 bool isFirstInSequence(Paragraph * par)
228 Paragraph const * dhook = depthHook(par, par->getDepth());
230 || dhook->layout() != par->layout()
231 || dhook->getDepth() != par->getDepth());
235 int getEndLabel(Paragraph * p)
238 Paragraph::depth_type par_depth = p->getDepth();
240 LyXLayout_ptr const & layout = par->layout();
241 int const endlabeltype = layout->endlabeltype;
243 if (endlabeltype != END_LABEL_NO_LABEL) {
247 Paragraph::depth_type const next_depth = p->next()->getDepth();
248 if (par_depth > next_depth ||
249 (par_depth == next_depth
250 && layout != p->next()->layout()))
256 par = outerHook(par);
258 par_depth = par->getDepth();
260 return END_LABEL_NO_LABEL;
266 ParagraphList::iterator
267 TeXEnvironment(Buffer const * buf,
268 ParagraphList const & paragraphs,
269 ParagraphList::iterator pit,
270 ostream & os, TexRow & texrow);
272 ParagraphList::iterator
273 TeXOnePar(Buffer const * buf,
274 ParagraphList const & paragraphs,
275 ParagraphList::iterator pit,
276 ostream & os, TexRow & texrow,
280 ParagraphList::iterator
281 TeXDeeper(Buffer const * buf,
282 ParagraphList const & paragraphs,
283 ParagraphList::iterator pit,
284 ostream & os, TexRow & texrow)
286 lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
287 ParagraphList::iterator par = pit;
289 while (par != paragraphs.end()&& par->params().depth() == pit->params().depth()) {
290 if (par->layout()->isEnvironment()) {
291 par = TeXEnvironment(buf, paragraphs, par,
294 par = TeXOnePar(buf, paragraphs, par,
298 lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
304 ParagraphList::iterator
305 TeXEnvironment(Buffer const * buf,
306 ParagraphList const & paragraphs,
307 ParagraphList::iterator pit,
308 ostream & os, TexRow & texrow)
310 lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl;
312 BufferParams const & bparams = buf->params;
314 LyXLayout_ptr const & style = pit->layout();
316 Language const * language = pit->getParLanguage(bparams);
317 Language const * doc_language = bparams.language;
318 Language const * previous_language =
319 (pit != paragraphs.begin())
320 ? boost::prior(pit)->getParLanguage(bparams)
322 if (language->babel() != previous_language->babel()) {
324 if (!lyxrc.language_command_end.empty() &&
325 previous_language->babel() != doc_language->babel()) {
326 os << subst(lyxrc.language_command_end, "$$lang",
327 previous_language->babel())
332 if (lyxrc.language_command_end.empty() ||
333 language->babel() != doc_language->babel()) {
334 os << subst(lyxrc.language_command_begin, "$$lang",
341 bool leftindent_open = false;
342 if (!pit->params().leftIndent().zero()) {
343 os << "\\begin{LyXParagraphLeftIndent}{" <<
344 pit->params().leftIndent().asLatexString() << "}\n";
346 leftindent_open = true;
349 if (style->isEnvironment()) {
350 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
351 os << "\\begin{" << style->latexname() << "}{"
352 << pit->params().labelWidthString() << "}\n";
353 } else if (style->labeltype == LABEL_BIBLIO) {
355 os << "\\begin{" << style->latexname() << "}{"
356 << bibitemWidest(buf)
358 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
359 os << "\\begin{" << style->latexname() << '}'
360 << style->latexparam() << '\n';
362 os << "\\begin{" << style->latexname() << '}'
363 << style->latexparam() << '\n';
366 ParagraphList::iterator par = pit;
368 par = TeXOnePar(buf, paragraphs, par, os, texrow, false);
370 if (par != paragraphs.end()&& par->params().depth() > pit->params().depth()) {
371 if (par->layout()->isParagraph()) {
374 // How to handle this? (Lgb)
375 //&& !suffixIs(os, "\n\n")
377 // There should be at least one '\n' already
378 // but we need there to be two for Standard
379 // paragraphs that are depth-increment'ed to be
380 // output correctly. However, tables can
381 // also be paragraphs so don't adjust them.
384 // Will it ever harm to have one '\n' too
385 // many? i.e. that we sometimes will have
386 // three in a row. (Lgb)
390 par = TeXDeeper(buf, paragraphs, par, os, texrow);
392 } while (par != paragraphs.end()
393 && par->layout() == pit->layout()
394 && par->params().depth() == pit->params().depth()
395 && par->params().leftIndent() == pit->params().leftIndent());
397 if (style->isEnvironment()) {
398 os << "\\end{" << style->latexname() << "}\n";
402 if (leftindent_open) {
403 os << "\\end{LyXParagraphLeftIndent}\n";
407 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
408 return par; // ale970302
412 InsetOptArg * optArgInset(Paragraph const & par)
415 InsetList::iterator it = par.insetlist.begin();
416 InsetList::iterator end = par.insetlist.end();
417 for (; it != end; ++it) {
418 Inset * ins = it.getInset();
419 if (ins->lyxCode() == Inset::OPTARG_CODE) {
420 return static_cast<InsetOptArg *>(ins);
427 ParagraphList::iterator
428 TeXOnePar(Buffer const * buf,
429 ParagraphList const & paragraphs,
430 ParagraphList::iterator pit,
431 ostream & os, TexRow & texrow,
434 lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << endl;
435 BufferParams const & bparams = buf->params;
437 Inset const * in = pit->inInset();
438 bool further_blank_line = false;
441 // well we have to check if we are in an inset with unlimited
442 // lenght (all in one row) if that is true then we don't allow
443 // any special options in the paragraph and also we don't allow
444 // any environment other then "Standard" to be valid!
445 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
446 style = pit->layout();
448 if (pit->params().startOfAppendix()) {
449 os << "\\appendix\n";
453 if (!pit->params().spacing().isDefault()
454 && (pit == paragraphs.begin() || !boost::prior(pit)->hasSameLayout(&*pit))) {
455 os << pit->params().spacing().writeEnvirBegin() << '\n';
459 if (style->isCommand()) {
464 if (pit->params().pagebreakTop()) {
466 further_blank_line = true;
468 if (pit->params().spaceTop().kind() != VSpace::NONE) {
469 os << pit->params().spaceTop().asLatexCommand(bparams);
470 further_blank_line = true;
473 if (pit->params().lineTop()) {
474 os << "\\lyxline{\\" << pit->getFont(bparams, 0, outerFont(pit, paragraphs)).latexSize() << '}'
475 << "\\vspace{-1\\parskip}";
476 further_blank_line = true;
479 if (further_blank_line) {
484 style = bparams.getLyXTextClass().defaultLayout();
487 Language const * language = pit->getParLanguage(bparams);
488 Language const * doc_language = bparams.language;
489 Language const * previous_language =
490 (pit != paragraphs.begin())
491 ? boost::prior(pit)->getParLanguage(bparams)
494 if (language->babel() != previous_language->babel()
495 // check if we already put language command in TeXEnvironment()
496 && !(style->isEnvironment()
497 && (pit == paragraphs.begin() ||
498 (boost::prior(pit)->layout() != pit->layout() &&
499 boost::prior(pit)->getDepth() <= pit->getDepth())
500 || boost::prior(pit)->getDepth() < pit->getDepth())))
502 if (!lyxrc.language_command_end.empty() &&
503 previous_language->babel() != doc_language->babel())
505 os << subst(lyxrc.language_command_end, "$$lang",
506 previous_language->babel())
511 if (lyxrc.language_command_end.empty() ||
512 language->babel() != doc_language->babel())
514 os << subst(lyxrc.language_command_begin, "$$lang",
521 if (bparams.inputenc == "auto" &&
522 language->encoding() != previous_language->encoding()) {
523 os << "\\inputencoding{"
524 << language->encoding()->LatexName()
529 switch (style->latextype) {
531 os << '\\' << style->latexname();
533 // Separate handling of optional argument inset.
534 if (style->optionalargs == 1) {
535 InsetOptArg * it = optArgInset(*pit);
537 it->latexOptional(buf, os, false, false);
540 os << style->latexparam();
542 case LATEX_ITEM_ENVIRONMENT:
543 case LATEX_LIST_ENVIRONMENT:
546 case LATEX_BIB_ENVIRONMENT:
547 // ignore this, the inset will write itself
553 bool need_par = pit->simpleTeXOnePar(buf, bparams,
554 outerFont(pit, paragraphs),
555 os, texrow, moving_arg);
557 // Make sure that \\par is done with the font of the last
558 // character if this has another size as the default.
559 // This is necessary because LaTeX (and LyX on the screen)
560 // calculates the space between the baselines according
561 // to this font. (Matthias)
563 // Is this really needed ? (Dekel)
564 // We do not need to use to change the font for the last paragraph
566 LyXFont const outerfont(outerFont(pit, paragraphs));
570 ? pit->getLayoutFont(bparams, outerfont)
571 : pit->getFont(bparams, pit->size() - 1, outerfont));
573 bool is_command = style->isCommand();
575 if (style->resfont.size() != font.size()
576 && boost::next(pit) != paragraphs.end()
580 os << "\\" << font.latexSize() << " \\par}";
581 } else if (need_par) {
583 } else if (is_command)
586 switch (style->latextype) {
587 case LATEX_ITEM_ENVIRONMENT:
588 case LATEX_LIST_ENVIRONMENT:
589 if (boost::next(pit) != paragraphs.end()
590 && (pit->params().depth() < boost::next(pit)->params().depth())) {
595 case LATEX_ENVIRONMENT:
596 // if its the last paragraph of the current environment
597 // skip it otherwise fall through
598 if (boost::next(pit) != paragraphs.end()
599 && (boost::next(pit)->layout() != pit->layout()
600 || boost::next(pit)->params().depth() != pit->params().depth()))
602 // fall through possible
604 // we don't need it for the last paragraph!!!
605 if (boost::next(pit) != paragraphs.end()) {
611 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
612 further_blank_line = false;
613 if (pit->params().lineBottom()) {
614 os << "\\lyxline{\\" << font.latexSize() << '}';
615 further_blank_line = true;
618 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
619 os << pit->params().spaceBottom().asLatexCommand(bparams);
620 further_blank_line = true;
623 if (pit->params().pagebreakBottom()) {
625 further_blank_line = true;
628 if (further_blank_line) {
633 if (!pit->params().spacing().isDefault()
634 && (boost::next(pit) == paragraphs.end()|| !boost::next(pit)->hasSameLayout(&*pit))) {
635 os << pit->params().spacing().writeEnvirEnd() << '\n';
640 // we don't need it for the last paragraph!!!
641 if (boost::next(pit) != paragraphs.end()) {
645 // Since \selectlanguage write the language to the aux file,
646 // we need to reset the language at the end of footnote or
649 if (language->babel() != doc_language->babel()) {
650 if (lyxrc.language_command_end.empty())
651 os << subst(lyxrc.language_command_begin,
653 doc_language->babel())
656 os << subst(lyxrc.language_command_end,
664 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
672 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
674 void latexParagraphs(Buffer const * buf,
675 ParagraphList const & paragraphs,
676 ParagraphList::iterator par,
677 ParagraphList::iterator endpar,
682 bool was_title = false;
683 bool already_title = false;
684 LyXTextClass const & tclass = buf->params.getLyXTextClass();
687 while (par != endpar) {
688 Inset * in = par->inInset();
689 // well we have to check if we are in an inset with unlimited
690 // length (all in one row) if that is true then we don't allow
691 // any special options in the paragraph and also we don't allow
692 // any environment other then "Standard" to be valid!
693 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
694 LyXLayout_ptr const & layout = par->layout();
696 if (layout->intitle) {
698 lyxerr <<"Error in latexParagraphs: You"
699 " should not mix title layouts"
700 " with normal ones." << endl;
701 } else if (!was_title) {
703 if (tclass.titletype() == TITLE_ENVIRONMENT) {
705 << tclass.titlename()
710 } else if (was_title && !already_title) {
711 if (tclass.titletype() == TITLE_ENVIRONMENT) {
712 ofs << "\\end{" << tclass.titlename()
716 ofs << "\\" << tclass.titlename()
720 already_title = true;
724 if (layout->isEnvironment() ||
725 !par->params().leftIndent().zero())
727 par = TeXEnvironment(buf, paragraphs, par, ofs, texrow);
729 par = TeXOnePar(buf, paragraphs, par, ofs, texrow, moving_arg);
732 par = TeXOnePar(buf, paragraphs, par, ofs, texrow, moving_arg);
735 // It might be that we only have a title in this document
736 if (was_title && !already_title) {
737 if (tclass.titletype() == TITLE_ENVIRONMENT) {
738 ofs << "\\end{" << tclass.titlename()
742 ofs << "\\" << tclass.titlename()
752 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
755 static Change change;
757 BufferParams const & bp = buf.params;
759 if (token[0] != '\\') {
760 string::const_iterator cit = token.begin();
761 for (; cit != token.end(); ++cit) {
762 par.insertChar(par.size(), (*cit), font, change);
764 } else if (token == "\\layout") {
766 string layoutname = lex.getString();
768 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
771 LyXTextClass const & tclass = bp.getLyXTextClass();
773 if (layoutname.empty()) {
774 layoutname = tclass.defaultLayoutName();
777 bool hasLayout = tclass.hasLayout(layoutname);
780 lyxerr << "Layout '" << layoutname << "' does not"
781 << " exist in textclass '" << tclass.name()
783 lyxerr << "Trying to use default layout instead."
785 layoutname = tclass.defaultLayoutName();
789 // The is the compability reading of layout caption.
790 if (compare_ascii_no_case(layoutname, "caption") == 0) {
791 // We expect that the par we are now working on is
792 // really inside a InsetText inside a InsetFloat.
793 // We also know that captions can only be
794 // one paragraph. (Lgb)
796 // We should now read until the next "\layout"
798 // This is probably not good enough, what if the
799 // caption is the last par in the document (Lgb)
800 istream & ist = lex.getStream();
806 if (prefixIs(line, "\\layout")) {
810 if (prefixIs(line, "\\begin_inset"))
812 if (prefixIs(line, "\\end_inset")) {
824 // Now we should have the whole layout in ss
825 // we should now be able to give this to the
827 ss << "\\end_inset\n";
829 // This seems like a bug in stringstream.
830 // We really should be able to use ss
832 istringstream is(ss.str());
834 tmplex.setStream(is);
835 Inset * inset = new InsetCaption;
836 inset->Read(this, tmplex);
837 par.insertInset(pos, inset, font);
841 par.layout(bp.getLyXTextClass()[layoutname]);
843 // Test whether the layout is obsolete.
844 LyXLayout_ptr const & layout = par.layout();
845 if (!layout->obsoleted_by().empty())
846 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
848 par.params().read(lex);
853 } else if (token == "\\end_inset") {
854 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
855 << "Missing \\begin_inset?.\n";
856 // Simply ignore this. The insets do not have
858 // But insets should read it, it is a part of
859 // the inset isn't it? Lgb.
860 } else if (token == "\\begin_inset") {
861 Inset * i = readInset(lex, buf);
862 par.insertInset(par.size(), i, font, change);
863 } else if (token == "\\family") {
865 font.setLyXFamily(lex.getString());
866 } else if (token == "\\series") {
868 font.setLyXSeries(lex.getString());
869 } else if (token == "\\shape") {
871 font.setLyXShape(lex.getString());
872 } else if (token == "\\size") {
874 font.setLyXSize(lex.getString());
875 } else if (token == "\\lang") {
877 string const tok = lex.getString();
878 Language const * lang = languages.getLanguage(tok);
880 font.setLanguage(lang);
882 font.setLanguage(bp.language);
883 lex.printError("Unknown language `$$Token'");
885 } else if (token == "\\numeric") {
887 font.setNumber(font.setLyXMisc(lex.getString()));
888 } else if (token == "\\emph") {
890 font.setEmph(font.setLyXMisc(lex.getString()));
891 } else if (token == "\\bar") {
893 string const tok = lex.getString();
896 font.setUnderbar(LyXFont::ON);
897 else if (tok == "no")
898 font.setUnderbar(LyXFont::OFF);
899 else if (tok == "default")
900 font.setUnderbar(LyXFont::INHERIT);
902 lex.printError("Unknown bar font flag "
904 } else if (token == "\\noun") {
906 font.setNoun(font.setLyXMisc(lex.getString()));
907 } else if (token == "\\color") {
909 font.setLyXColor(lex.getString());
910 } else if (token == "\\SpecialChar") {
911 LyXLayout_ptr const & layout = par.layout();
913 // Insets don't make sense in a free-spacing context! ---Kayvan
914 if (layout->free_spacing || par.isFreeSpacing()) {
917 string const next_token = lex.getString();
918 if (next_token == "\\-") {
919 par.insertChar(par.size(), '-', font, change);
920 } else if (next_token == "~") {
921 par.insertChar(par.size(), ' ', font, change);
923 lex.printError("Token `$$Token' "
925 "paragraph layout!");
929 Inset * inset = new InsetSpecialChar;
930 inset->read(&buf, lex);
931 par.insertInset(par.size(), inset, font, change);
933 } else if (token == "\\i") {
934 Inset * inset = new InsetLatexAccent;
935 inset->read(&buf, lex);
936 par.insertInset(par.size(), inset, font, change);
937 } else if (token == "\\backslash") {
938 par.insertChar(par.size(), '\\', font, change);
939 } else if (token == "\\newline") {
940 Inset * inset = new InsetNewline;
941 inset->read(&buf, lex);
942 par.insertInset(par.size(), inset, font, change);
943 } else if (token == "\\LyXTable") {
944 Inset * inset = new InsetTabular(buf);
945 inset->read(&buf, lex);
946 par.insertInset(par.size(), inset, font, change);
947 } else if (token == "\\bibitem") {
948 InsetCommandParams p("bibitem", "dummy");
949 InsetBibitem * inset = new InsetBibitem(p);
950 inset->read(&buf, lex);
951 par.insertInset(par.size(), inset, font, change);
952 } else if (token == "\\hfill") {
953 par.insertInset(par.size(), new InsetHFill(), font, change);
954 } else if (token == "\\change_unchanged") {
955 // Hack ! Needed for empty paragraphs :/
956 // FIXME: is it still ??
959 change = Change(Change::UNCHANGED);
960 } else if (token == "\\change_inserted") {
962 istringstream istr(lex.getString());
967 change = Change(Change::INSERTED, bp.author_map[aid], ct);
968 } else if (token == "\\change_deleted") {
970 istringstream istr(lex.getString());
975 change = Change(Change::DELETED, bp.author_map[aid], ct);
979 boost::format fmt(_("Unknown token: %1$s %2$s\n"));
980 fmt % token % lex.getString();
981 string const s = fmt.str();
983 string const s = _("Unknown token: ") + token
984 + ' ' + lex.getString() + '\n';
986 // we can do this here this way because we're actually reading
987 // the buffer and don't care about LyXText right now.
988 InsetError * inset = new InsetError(s);
989 par.insertInset(par.size(), inset, font);
998 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
1003 string token = lex.getString();
1005 while (lex.isOK()) {
1007 unknown += readParToken(buf, par, lex, token);
1010 token = lex.getString();
1015 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1016 << token << '\'' << endl;
1018 // reached the next paragraph. FIXME: really we should
1019 // change the file format to indicate the end of a par
1020 // clearly, but for now, this hack will do
1021 if (token == "\\layout" || token == "\\the_end"
1022 || token == "\\end_inset" || token == "\\begin_deeper"
1023 || token == "\\end_deeper") {
1024 lex.pushToken(token);
1033 LyXFont const outerFont(ParagraphList::iterator pit,
1034 ParagraphList const & /*plist*/)
1036 Paragraph::depth_type par_depth = pit->getDepth();
1037 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1039 // Resolve against environment font information
1040 Paragraph * par = &*pit;
1041 while (par && par_depth && !tmpfont.resolved()) {
1042 par = outerHook(par);
1044 tmpfont.realize(par->layout()->font);
1045 par_depth = par->getDepth();
1053 LyXFont const realizeFont(LyXFont const & font,
1054 BufferParams const & params)
1056 LyXTextClass const & tclass = params.getLyXTextClass();
1057 LyXFont tmpfont(font);
1058 tmpfont.realize(tclass.defaultfont());