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"
18 #include "latexrunparams.h"
27 #include "support/lstrings.h"
28 #include "insets/insetoptarg.h"
29 #include "insets/insetcommandparams.h"
30 #include "insets/insetbibitem.h"
31 #include "insets/insetspace.h"
32 #include "insets/insetspecialchar.h"
33 #include "insets/insetlatexaccent.h"
34 #include "insets/insettabular.h"
35 #include "insets/insethfill.h"
36 #include "insets/inseterror.h"
37 #include "insets/insetnewline.h"
39 extern string bibitemWidest(Buffer const *);
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->layout()->keepempty && 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 = 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())
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 != 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) == 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 != 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 != 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, false);
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 != 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, false);
383 if (par != 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 != 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::iterator it = par.insetlist.begin();
430 InsetList::iterator end = par.insetlist.end();
431 for (; it != end; ++it) {
432 Inset * ins = it.getInset();
433 if (ins->lyxCode() == Inset::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 Inset 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 == 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 != 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 == 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,
559 os << style->latexparam();
561 case LATEX_ITEM_ENVIRONMENT:
562 case LATEX_LIST_ENVIRONMENT:
565 case LATEX_BIB_ENVIRONMENT:
566 // ignore this, the inset will write itself
573 bool need_par = pit->simpleTeXOnePar(buf, bparams,
574 outerFont(pit, paragraphs),
575 os, texrow, runparams,
578 // Make sure that \\par is done with the font of the last
579 // character if this has another size as the default.
580 // This is necessary because LaTeX (and LyX on the screen)
581 // calculates the space between the baselines according
582 // to this font. (Matthias)
584 // Is this really needed ? (Dekel)
585 // We do not need to use to change the font for the last paragraph
587 LyXFont const outerfont(outerFont(pit, paragraphs));
591 ? pit->getLayoutFont(bparams, outerfont)
592 : pit->getFont(bparams, pit->size() - 1, outerfont));
594 bool is_command = style->isCommand();
596 if (style->resfont.size() != font.size()
597 && boost::next(pit) != paragraphs.end()
601 os << "\\" << font.latexSize() << " \\par}";
602 } else if (need_par) {
604 } else if (is_command)
607 switch (style->latextype) {
608 case LATEX_ITEM_ENVIRONMENT:
609 case LATEX_LIST_ENVIRONMENT:
610 if (boost::next(pit) != paragraphs.end()
611 && (pit->params().depth() < boost::next(pit)->params().depth())) {
616 case LATEX_ENVIRONMENT:
617 // if its the last paragraph of the current environment
618 // skip it otherwise fall through
619 if (boost::next(pit) != paragraphs.end()
620 && (boost::next(pit)->layout() != pit->layout()
621 || boost::next(pit)->params().depth() != pit->params().depth()))
623 // fall through possible
625 // we don't need it for the last paragraph!!!
626 if (boost::next(pit) != paragraphs.end()) {
632 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
633 further_blank_line = false;
634 if (pit->params().lineBottom()) {
635 os << "\\lyxline{\\" << font.latexSize() << '}';
636 further_blank_line = true;
639 if (pit->params().spaceBottom().kind() != VSpace::NONE) {
640 os << pit->params().spaceBottom().asLatexCommand(bparams);
641 further_blank_line = true;
644 if (pit->params().pagebreakBottom()) {
646 further_blank_line = true;
649 if (further_blank_line) {
654 if (!pit->params().spacing().isDefault()
655 && (boost::next(pit) == paragraphs.end()|| !boost::next(pit)->hasSameLayout(*pit))) {
656 os << pit->params().spacing().writeEnvirEnd() << '\n';
661 // we don't need it for the last paragraph!!!
662 if (boost::next(pit) != paragraphs.end()) {
666 // Since \selectlanguage write the language to the aux file,
667 // we need to reset the language at the end of footnote or
670 if (language->babel() != doc_language->babel()) {
671 if (lyxrc.language_command_end.empty())
672 os << subst(lyxrc.language_command_begin,
674 doc_language->babel())
677 os << subst(lyxrc.language_command_end,
685 lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
693 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
695 void latexParagraphs(Buffer const * buf,
696 ParagraphList const & paragraphs,
699 LatexRunParams const & runparams,
700 string const & everypar)
702 bool was_title = false;
703 bool already_title = false;
704 LyXTextClass const & tclass = buf->params.getLyXTextClass();
705 ParagraphList::iterator par = paragraphs.begin();
706 ParagraphList::iterator endpar = paragraphs.end();
709 while (par != endpar) {
710 Inset * in = par->inInset();
711 // well we have to check if we are in an inset with unlimited
712 // length (all in one row) if that is true then we don't allow
713 // any special options in the paragraph and also we don't allow
714 // any environment other then "Standard" to be valid!
715 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
716 LyXLayout_ptr const & layout = par->layout();
718 if (layout->intitle) {
720 lyxerr <<"Error in latexParagraphs: You"
721 " should not mix title layouts"
722 " with normal ones." << endl;
723 } else if (!was_title) {
725 if (tclass.titletype() == TITLE_ENVIRONMENT) {
727 << tclass.titlename()
732 } else if (was_title && !already_title) {
733 if (tclass.titletype() == TITLE_ENVIRONMENT) {
734 os << "\\end{" << tclass.titlename()
738 os << "\\" << tclass.titlename()
742 already_title = true;
746 if (layout->is_environment) {
747 par = TeXOnePar(buf, paragraphs, par, os, texrow,
748 runparams, everypar);
749 } else if (layout->isEnvironment() ||
750 !par->params().leftIndent().zero())
752 par = TeXEnvironment(buf, paragraphs, par, os,
755 par = TeXOnePar(buf, paragraphs, par, os, texrow,
756 runparams, everypar);
759 par = TeXOnePar(buf, paragraphs, par, os, texrow,
760 runparams, everypar);
763 // It might be that we only have a title in this document
764 if (was_title && !already_title) {
765 if (tclass.titletype() == TITLE_ENVIRONMENT) {
766 os << "\\end{" << tclass.titlename()
770 os << "\\" << tclass.titlename()
780 int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token)
783 static Change change;
785 BufferParams const & bp = buf.params;
787 if (token[0] != '\\') {
788 string::const_iterator cit = token.begin();
789 for (; cit != token.end(); ++cit) {
790 par.insertChar(par.size(), (*cit), font, change);
792 } else if (token == "\\layout") {
794 string layoutname = lex.getString();
796 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
799 LyXTextClass const & tclass = bp.getLyXTextClass();
801 if (layoutname.empty()) {
802 layoutname = tclass.defaultLayoutName();
805 bool hasLayout = tclass.hasLayout(layoutname);
808 lyxerr << "Layout '" << layoutname << "' does not"
809 << " exist in textclass '" << tclass.name()
811 lyxerr << "Trying to use default layout instead."
813 layoutname = tclass.defaultLayoutName();
817 // The is the compability reading of layout caption.
818 if (compare_ascii_no_case(layoutname, "caption") == 0) {
819 // We expect that the par we are now working on is
820 // really inside a InsetText inside a InsetFloat.
821 // We also know that captions can only be
822 // one paragraph. (Lgb)
824 // We should now read until the next "\layout"
826 // This is probably not good enough, what if the
827 // caption is the last par in the document (Lgb)
828 istream & ist = lex.getStream();
834 if (prefixIs(line, "\\layout")) {
838 if (prefixIs(line, "\\begin_inset"))
840 if (prefixIs(line, "\\end_inset")) {
852 // Now we should have the whole layout in ss
853 // we should now be able to give this to the
855 ss << "\\end_inset\n";
857 // This seems like a bug in stringstream.
858 // We really should be able to use ss
860 istringstream is(ss.str());
862 tmplex.setStream(is);
863 Inset * inset = new InsetCaption;
864 inset->Read(this, tmplex);
865 par.insertInset(pos, inset, font);
869 par.layout(bp.getLyXTextClass()[layoutname]);
871 // Test whether the layout is obsolete.
872 LyXLayout_ptr const & layout = par.layout();
873 if (!layout->obsoleted_by().empty())
874 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
876 par.params().read(lex);
881 } else if (token == "\\end_inset") {
882 lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
883 << "Missing \\begin_inset?.\n";
884 // Simply ignore this. The insets do not have
886 // But insets should read it, it is a part of
887 // the inset isn't it? Lgb.
888 } else if (token == "\\begin_inset") {
889 Inset * i = readInset(lex, buf);
890 par.insertInset(par.size(), i, font, change);
891 } else if (token == "\\family") {
893 font.setLyXFamily(lex.getString());
894 } else if (token == "\\series") {
896 font.setLyXSeries(lex.getString());
897 } else if (token == "\\shape") {
899 font.setLyXShape(lex.getString());
900 } else if (token == "\\size") {
902 font.setLyXSize(lex.getString());
903 } else if (token == "\\lang") {
905 string const tok = lex.getString();
906 Language const * lang = languages.getLanguage(tok);
908 font.setLanguage(lang);
910 font.setLanguage(bp.language);
911 lex.printError("Unknown language `$$Token'");
913 } else if (token == "\\numeric") {
915 font.setNumber(font.setLyXMisc(lex.getString()));
916 } else if (token == "\\emph") {
918 font.setEmph(font.setLyXMisc(lex.getString()));
919 } else if (token == "\\bar") {
921 string const tok = lex.getString();
924 font.setUnderbar(LyXFont::ON);
925 else if (tok == "no")
926 font.setUnderbar(LyXFont::OFF);
927 else if (tok == "default")
928 font.setUnderbar(LyXFont::INHERIT);
930 lex.printError("Unknown bar font flag "
932 } else if (token == "\\noun") {
934 font.setNoun(font.setLyXMisc(lex.getString()));
935 } else if (token == "\\color") {
937 font.setLyXColor(lex.getString());
938 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
939 LyXLayout_ptr const & layout = par.layout();
941 // Insets don't make sense in a free-spacing context! ---Kayvan
942 if (layout->free_spacing || par.isFreeSpacing()) {
943 if (token == "\\InsetSpace")
944 par.insertChar(par.size(), ' ', font, change);
945 else if (lex.isOK()) {
947 string const next_token = lex.getString();
948 if (next_token == "\\-")
949 par.insertChar(par.size(), '-', font, change);
951 lex.printError("Token `$$Token' "
953 "paragraph layout!");
958 if (token == "\\SpecialChar" )
959 inset = new InsetSpecialChar;
961 inset = new InsetSpace;
962 inset->read(&buf, lex);
963 par.insertInset(par.size(), inset, font, change);
965 } else if (token == "\\i") {
966 Inset * inset = new InsetLatexAccent;
967 inset->read(&buf, lex);
968 par.insertInset(par.size(), inset, font, change);
969 } else if (token == "\\backslash") {
970 par.insertChar(par.size(), '\\', font, change);
971 } else if (token == "\\newline") {
972 Inset * inset = new InsetNewline;
973 inset->read(&buf, lex);
974 par.insertInset(par.size(), inset, font, change);
975 } else if (token == "\\LyXTable") {
976 Inset * inset = new InsetTabular(buf);
977 inset->read(&buf, lex);
978 par.insertInset(par.size(), inset, font, change);
979 } else if (token == "\\bibitem") {
980 InsetCommandParams p("bibitem", "dummy");
981 InsetBibitem * inset = new InsetBibitem(p);
982 inset->read(&buf, lex);
983 par.insertInset(par.size(), inset, font, change);
984 } else if (token == "\\hfill") {
985 par.insertInset(par.size(), new InsetHFill(), font, change);
986 } else if (token == "\\change_unchanged") {
987 // Hack ! Needed for empty paragraphs :/
988 // FIXME: is it still ??
991 change = Change(Change::UNCHANGED);
992 } else if (token == "\\change_inserted") {
994 istringstream is(STRCONV(lex.getString()));
998 change = Change(Change::INSERTED, bp.author_map[aid], ct);
999 } else if (token == "\\change_deleted") {
1001 istringstream is(STRCONV(lex.getString()));
1005 change = Change(Change::DELETED, bp.author_map[aid], ct);
1008 string const s = bformat(_("Unknown token: %1$s %2$s\n"),
1009 token, lex.getString());
1010 // we can do this here this way because we're actually reading
1011 // the buffer and don't care about LyXText right now.
1012 par.insertInset(par.size(), new InsetError(s), font);
1021 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
1026 string token = lex.getString();
1028 while (lex.isOK()) {
1030 unknown += readParToken(buf, par, lex, token);
1033 token = lex.getString();
1038 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
1039 << token << '\'' << endl;
1041 // reached the next paragraph. FIXME: really we should
1042 // change the file format to indicate the end of a par
1043 // clearly, but for now, this hack will do
1044 if (token == "\\layout" || token == "\\the_end"
1045 || token == "\\end_inset" || token == "\\begin_deeper"
1046 || token == "\\end_deeper") {
1047 lex.pushToken(token);
1056 LyXFont const outerFont(ParagraphList::iterator pit,
1057 ParagraphList const & plist)
1059 Paragraph::depth_type par_depth = pit->getDepth();
1060 LyXFont tmpfont(LyXFont::ALL_INHERIT);
1062 // Resolve against environment font information
1063 while (pit != plist.end() &&
1064 par_depth && !tmpfont.resolved()) {
1065 pit = outerHook(pit, plist);
1066 if (pit != plist.end()) {
1067 tmpfont.realize(pit->layout()->font);
1068 par_depth = pit->getDepth();
1076 LyXFont const realizeFont(LyXFont const & font,
1077 BufferParams const & params)
1079 LyXTextClass const & tclass = params.getLyXTextClass();
1080 LyXFont tmpfont(font);
1081 tmpfont.realize(tclass.defaultfont());