]> git.lyx.org Git - lyx.git/blob - src/paragraph_pimpl.C
Updates from Bennett and myself.
[lyx.git] / src / paragraph_pimpl.C
1 /**
2  * \file paragraph_pimpl.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author John Levon
9  * \author André Pönitz
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "paragraph_pimpl.h"
17 #include "paragraph.h"
18
19 #include "bufferparams.h"
20 #include "debug.h"
21 #include "encoding.h"
22 #include "language.h"
23 #include "LaTeXFeatures.h"
24 #include "LColor.h"
25 #include "lyxlength.h"
26 #include "lyxrc.h"
27 #include "outputparams.h"
28 #include "texrow.h"
29
30 #include <boost/next_prior.hpp>
31
32
33 namespace lyx {
34
35 using std::endl;
36 using std::upper_bound;
37 using std::lower_bound;
38 using std::string;
39
40
41 // Initialization of the counter for the paragraph id's,
42 unsigned int Paragraph::Pimpl::paragraph_id = 0;
43
44 namespace {
45
46 struct special_phrase {
47         string phrase;
48         docstring macro;
49         bool builtin;
50 };
51
52 special_phrase const special_phrases[] = {
53         { "LyX", from_ascii("\\LyX{}"), false },
54         { "TeX", from_ascii("\\TeX{}"), true },
55         { "LaTeX2e", from_ascii("\\LaTeXe{}"), true },
56         { "LaTeX", from_ascii("\\LaTeX{}"), true },
57 };
58
59 size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
60
61 } // namespace anon
62
63
64 Paragraph::Pimpl::Pimpl(Paragraph * owner)
65         : owner_(owner)
66 {
67         inset_owner = 0;
68         id_ = paragraph_id++;
69 }
70
71
72 Paragraph::Pimpl::Pimpl(Pimpl const & p, Paragraph * owner)
73         : params(p.params), changes_(p.changes_), owner_(owner)
74 {
75         inset_owner = p.inset_owner;
76         fontlist = p.fontlist;
77         id_ = paragraph_id++;
78 }
79
80
81 bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const
82 {
83         BOOST_ASSERT(start >= 0 && start <= size());
84         BOOST_ASSERT(end > start && end <= size() + 1);
85
86         return changes_.isChanged(start, end);
87 }
88
89
90 bool Paragraph::Pimpl::isMergedOnEndOfParDeletion(bool trackChanges) const {
91         // keep the logic here in sync with the logic of eraseChars()
92
93         if (!trackChanges) {
94                 return true;
95         }
96
97         Change change = changes_.lookup(size());
98
99         return change.type == Change::INSERTED && change.author == 0;
100 }
101
102
103 void Paragraph::Pimpl::setChange(Change const & change)
104 {
105         // beware of the imaginary end-of-par character!
106         changes_.set(change, 0, size() + 1);
107
108         /*
109          * Propagate the change recursively - but not in case of DELETED!
110          *
111          * Imagine that your co-author makes changes in an existing inset. He
112          * sends your document to you and you come to the conclusion that the
113          * inset should go completely. If you erase it, LyX must not delete all
114          * text within the inset. Otherwise, the change tracked insertions of
115          * your co-author get lost and there is no way to restore them later.
116          *
117          * Conclusion: An inset's content should remain untouched if you delete it
118          */
119
120         if (change.type != Change::DELETED) {
121                 for (pos_type pos = 0; pos < size(); ++pos) {
122                         if (owner_->isInset(pos)) {
123                                 owner_->getInset(pos)->setChange(change);
124                         }
125                 }
126         }
127 }
128
129
130 void Paragraph::Pimpl::setChange(pos_type pos, Change const & change)
131 {
132         BOOST_ASSERT(pos >= 0 && pos <= size());
133
134         changes_.set(change, pos);
135
136         // see comment in setChange(Change const &) above
137
138         if (change.type != Change::DELETED &&
139             pos < size() && owner_->isInset(pos)) {
140                 owner_->getInset(pos)->setChange(change);
141         }
142 }
143
144
145 Change const Paragraph::Pimpl::lookupChange(pos_type pos) const
146 {
147         BOOST_ASSERT(pos >= 0 && pos <= size());
148
149         return changes_.lookup(pos);
150 }
151
152
153 void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end)
154 {
155         BOOST_ASSERT(start >= 0 && start <= size());
156         BOOST_ASSERT(end > start && end <= size() + 1);
157         
158         for (pos_type pos = start; pos < end; ++pos) {
159                 switch (lookupChange(pos).type) {
160                         case Change::UNCHANGED:
161                                 break;
162
163                         case Change::INSERTED:
164                                 changes_.set(Change(Change::UNCHANGED), pos);
165                                 break;
166
167                         case Change::DELETED:
168                                 // Suppress access to non-existent
169                                 // "end-of-paragraph char"
170                                 if (pos < size()) {
171                                         eraseChar(pos, false);
172                                         --end;
173                                         --pos;
174                                 }
175                                 break;
176                 }
177
178                 // also accept changes in nested insets
179                 if (pos < size() && owner_->isInset(pos)) {
180                         owner_->getInset(pos)->acceptChanges();
181                 }
182         }
183 }
184
185
186 void Paragraph::Pimpl::rejectChanges(pos_type start, pos_type end)
187 {
188         BOOST_ASSERT(start >= 0 && start <= size());
189         BOOST_ASSERT(end > start && end <= size() + 1);
190
191         for (pos_type pos = start; pos < end; ++pos) {
192                 switch (lookupChange(pos).type) {
193                         case Change::UNCHANGED:
194                                 // also reject changes inside of insets
195                                 if (pos < size() && owner_->isInset(pos)) {
196                                         owner_->getInset(pos)->rejectChanges();
197                                 }
198                                 break;
199
200                         case Change::INSERTED:
201                                 // Suppress access to non-existent
202                                 // "end-of-paragraph char"
203                                 if (pos < size()) {
204                                         eraseChar(pos, false);
205                                         --end;
206                                         --pos;
207                                 }
208                                 break;
209
210                         case Change::DELETED:
211                                 changes_.set(Change(Change::UNCHANGED), pos);
212
213                                 // Do NOT reject changes within a deleted inset!
214                                 // There may be insertions of a co-author inside of it!
215
216                                 break;
217                 }
218         }
219 }
220
221
222 Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
223 {
224         BOOST_ASSERT(pos >= 0 && pos <= size());
225
226         return owner_->getChar(pos);
227 }
228
229
230 void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & change)
231 {
232         BOOST_ASSERT(pos >= 0 && pos <= size());
233
234         // track change
235         changes_.insert(change, pos);
236
237         // This is actually very common when parsing buffers (and
238         // maybe inserting ascii text)
239         if (pos == size()) {
240                 // when appending characters, no need to update tables
241                 owner_->text_.push_back(c);
242                 return;
243         }
244
245         owner_->text_.insert(owner_->text_.begin() + pos, c);
246
247         // Update the font table.
248         FontTable search_font(pos, LyXFont());
249         for (FontList::iterator it 
250               = lower_bound(fontlist.begin(), fontlist.end(), search_font, matchFT());
251              it != fontlist.end(); ++it)
252         {
253                 it->pos(it->pos() + 1);
254         }
255
256         // Update the insets
257         owner_->insetlist.increasePosAfterPos(pos);
258 }
259
260
261 void Paragraph::Pimpl::insertInset(pos_type pos, InsetBase * inset,
262                                    Change const & change)
263 {
264         BOOST_ASSERT(inset);
265         BOOST_ASSERT(pos >= 0 && pos <= size());
266
267         insertChar(pos, META_INSET, change);
268         BOOST_ASSERT(owner_->text_[pos] == META_INSET);
269
270         // Add a new entry in the insetlist.
271         owner_->insetlist.insert(inset, pos);
272 }
273
274
275 bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
276 {
277         BOOST_ASSERT(pos >= 0 && pos <= size());
278
279         // keep the logic here in sync with the logic of isMergedOnEndOfParDeletion()
280
281         if (trackChanges) {
282                 Change change = changes_.lookup(pos);
283
284                 // set the character to DELETED if 
285                 //  a) it was previously unchanged or
286                 //  b) it was inserted by a co-author
287
288                 if (change.type == Change::UNCHANGED ||
289                     (change.type == Change::INSERTED && change.author != 0)) {
290                         setChange(pos, Change(Change::DELETED));
291                         return false;
292                 }
293
294                 if (change.type == Change::DELETED)
295                         return false;
296         }
297
298         // Don't physically access the imaginary end-of-paragraph character.
299         // eraseChar() can only mark it as DELETED. A physical deletion of
300         // end-of-par must be handled externally.
301         if (pos == size()) {
302                 return false;
303         }
304
305         // track change
306         changes_.erase(pos);
307
308         // if it is an inset, delete the inset entry
309         if (owner_->text_[pos] == Paragraph::META_INSET) {
310                 owner_->insetlist.erase(pos);
311         }
312
313         owner_->text_.erase(owner_->text_.begin() + pos);
314
315         // Erase entries in the tables.
316         FontTable search_font(pos, LyXFont());
317
318         FontList::iterator it =
319                 lower_bound(fontlist.begin(),
320                             fontlist.end(),
321                             search_font, matchFT());
322         if (it != fontlist.end() && it->pos() == pos &&
323             (pos == 0 ||
324              (it != fontlist.begin()
325               && boost::prior(it)->pos() == pos - 1))) {
326                 // If it is a multi-character font
327                 // entry, we just make it smaller
328                 // (see update below), otherwise we
329                 // should delete it.
330                 unsigned int const i = it - fontlist.begin();
331                 fontlist.erase(fontlist.begin() + i);
332                 it = fontlist.begin() + i;
333                 if (i > 0 && i < fontlist.size() &&
334                     fontlist[i - 1].font() == fontlist[i].font()) {
335                         fontlist.erase(fontlist.begin() + i - 1);
336                         it = fontlist.begin() + i - 1;
337                 }
338         }
339
340         // Update all other entries
341         FontList::iterator fend = fontlist.end();
342         for (; it != fend; ++it)
343                 it->pos(it->pos() - 1);
344
345         // Update the insetlist
346         owner_->insetlist.decreasePosAfterPos(pos);
347
348         return true;
349 }
350
351
352 int Paragraph::Pimpl::eraseChars(pos_type start, pos_type end, bool trackChanges)
353 {
354         BOOST_ASSERT(start >= 0 && start <= size());
355         BOOST_ASSERT(end >= start && end <= size() + 1);
356
357         pos_type i = start;
358         for (pos_type count = end - start; count; --count) {
359                 if (!eraseChar(i, trackChanges))
360                         ++i;
361         }
362         return end - i;
363 }
364
365
366 void Paragraph::Pimpl::simpleTeXBlanks(odocstream & os, TexRow & texrow,
367                                        pos_type const i,
368                                        unsigned int & column,
369                                        LyXFont const & font,
370                                        LyXLayout const & style)
371 {
372         if (style.pass_thru)
373                 return;
374
375         if (column > lyxrc.ascii_linelen
376             && i
377             && getChar(i - 1) != ' '
378             && (i < size() - 1)
379             // same in FreeSpacing mode
380             && !owner_->isFreeSpacing()
381             // In typewriter mode, we want to avoid
382             // ! . ? : at the end of a line
383             && !(font.family() == LyXFont::TYPEWRITER_FAMILY
384                  && (getChar(i - 1) == '.'
385                      || getChar(i - 1) == '?'
386                      || getChar(i - 1) == ':'
387                      || getChar(i - 1) == '!'))) {
388                 os << '\n';
389                 texrow.newline();
390                 texrow.start(owner_->id(), i + 1);
391                 column = 0;
392         } else if (style.free_spacing) {
393                 os << '~';
394         } else {
395                 os << ' ';
396         }
397 }
398
399
400 bool Paragraph::Pimpl::isTextAt(string const & str, pos_type pos) const
401 {
402         pos_type const len = str.length();
403
404         // is the paragraph large enough?
405         if (pos + len > size())
406                 return false;
407
408         // does the wanted text start at point?
409         for (string::size_type i = 0; i < str.length(); ++i) {
410                 if (str[i] != owner_->text_[pos + i])
411                         return false;
412         }
413
414         // is there a font change in middle of the word?
415         FontList::const_iterator cit = fontlist.begin();
416         FontList::const_iterator end = fontlist.end();
417         for (; cit != end; ++cit) {
418                 if (cit->pos() >= pos)
419                         break;
420         }
421         if (cit != end && pos + len - 1 > cit->pos())
422                 return false;
423
424         return true;
425 }
426
427
428 void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
429                                              BufferParams const & bparams,
430                                              odocstream & os,
431                                              TexRow & texrow,
432                                              OutputParams const & runparams,
433                                              LyXFont & font,
434                                              LyXFont & running_font,
435                                              LyXFont & basefont,
436                                              LyXFont const & outerfont,
437                                              bool & open_font,
438                                              Change::Type & running_change,
439                                              LyXLayout const & style,
440                                              pos_type & i,
441                                              unsigned int & column,
442                                              value_type const c)
443 {
444         if (style.pass_thru) {
445                 if (c != Paragraph::META_INSET) {
446                         if (c != '\0')
447                                 os.put(c);
448                 } else
449                         owner_->getInset(i)->plaintext(buf, os, runparams);
450                 return;
451         }
452
453         // Two major modes:  LaTeX or plain
454         // Handle here those cases common to both modes
455         // and then split to handle the two modes separately.
456         switch (c) {
457         case Paragraph::META_INSET: {
458                 InsetBase * inset = owner_->getInset(i);
459
460                 // FIXME: remove this check
461                 if (!inset)
462                         break;
463
464                 // FIXME: move this to InsetNewline::latex
465                 if (inset->lyxCode() == InsetBase::NEWLINE_CODE) {
466                         // newlines are handled differently here than
467                         // the default in simpleTeXSpecialChars().
468                         if (!style.newline_allowed) {
469                                 os << '\n';
470                         } else {
471                                 if (open_font) {
472                                         column += running_font.latexWriteEndChanges(os, basefont, basefont);
473                                         open_font = false;
474                                 }
475                                 basefont = owner_->getLayoutFont(bparams, outerfont);
476                                 running_font = basefont;
477
478                                 if (font.family() == LyXFont::TYPEWRITER_FAMILY)
479                                         os << '~';
480
481                                 if (runparams.moving_arg)
482                                         os << "\\protect ";
483
484                                 os << "\\\\\n";
485                         }
486                         texrow.newline();
487                         texrow.start(owner_->id(), i + 1);
488                         column = 0;
489                         break;
490                 }
491
492                 // output change tracking marks only if desired,
493                 // if dvipost is installed,
494                 // and with dvi/ps (other formats don't work)
495                 LaTeXFeatures features(buf, bparams, runparams);
496                 bool const output = bparams.outputChanges
497                         && runparams.flavor == OutputParams::LATEX
498                         && features.isAvailable("dvipost");
499
500                 if (inset->canTrackChanges()) {
501                         column += Changes::latexMarkChange(os, running_change,
502                                 Change::UNCHANGED, output);
503                         running_change = Change::UNCHANGED;
504                 }
505
506                 bool close = false;
507                 odocstream::pos_type const len = os.tellp();
508
509                 if ((inset->lyxCode() == InsetBase::GRAPHICS_CODE
510                      || inset->lyxCode() == InsetBase::MATH_CODE
511                      || inset->lyxCode() == InsetBase::URL_CODE)
512                     && running_font.isRightToLeft()) {
513                         os << "\\L{";
514                         close = true;
515                 }
516
517 #ifdef WITH_WARNINGS
518 #warning Bug: we can have an empty font change here!
519 // if there has just been a font change, we are going to close it
520 // right now, which means stupid latex code like \textsf{}. AFAIK,
521 // this does not harm dvi output. A minor bug, thus (JMarc)
522 #endif
523                 // some insets cannot be inside a font change command
524                 if (open_font && inset->noFontChange()) {
525                         column +=running_font.
526                                 latexWriteEndChanges(os,
527                                                      basefont,
528                                                      basefont);
529                         open_font = false;
530                         basefont = owner_->getLayoutFont(bparams, outerfont);
531                         running_font = basefont;
532                 }
533
534                 int tmp = inset->latex(buf, os, runparams);
535
536                 if (close)
537                         os << '}';
538
539                 if (tmp) {
540                         for (int j = 0; j < tmp; ++j) {
541                                 texrow.newline();
542                         }
543                         texrow.start(owner_->id(), i + 1);
544                         column = 0;
545                 } else {
546                         column += os.tellp() - len;
547                 }
548         }
549         break;
550
551         default:
552                 // And now for the special cases within each mode
553
554                 switch (c) {
555                 case '\\':
556                         os << "\\textbackslash{}";
557                         column += 15;
558                         break;
559
560                 // The following characters could be written literally in latin1, but they
561                 // would be wrongly converted on systems where char is signed, so we give
562                 // the code points.
563                 // This also makes us independant from the encoding of this source file.
564                 case 0xb1:    // ± PLUS-MINUS SIGN
565                 case 0xb2:    // ² SUPERSCRIPT TWO
566                 case 0xb3:    // ³ SUPERSCRIPT THREE
567                 case 0xd7:    // × MULTIPLICATION SIGN
568                 case 0xf7:    // ÷ DIVISION SIGN
569                 case 0xb9:    // ¹ SUPERSCRIPT ONE
570                 case 0xac:    // ¬ NOT SIGN
571                 case 0xb5:    // µ MICRO SIGN
572                         if ((bparams.inputenc == "latin1" ||
573                              bparams.inputenc == "latin9") ||
574                             (bparams.inputenc == "auto" &&
575                              (font.language()->encoding()->latexName()
576                               == "latin1" ||
577                               font.language()->encoding()->latexName()
578                               == "latin9"))) {
579                                 os << "\\ensuremath{";
580                                 os.put(c);
581                                 os << '}';
582                                 column += 13;
583                         } else {
584                                 os.put(c);
585                         }
586                         break;
587
588                 case '|': case '<': case '>':
589                         // In T1 encoding, these characters exist
590                         if (lyxrc.fontenc == "T1") {
591                                 os.put(c);
592                                 //... but we should avoid ligatures
593                                 if ((c == '>' || c == '<')
594                                     && i <= size() - 2
595                                     && getChar(i + 1) == c) {
596                                         //os << "\\textcompwordmark{}";
597                                         // Jean-Marc, have a look at
598                                         // this. I think this works
599                                         // equally well:
600                                         os << "\\,{}";
601                                         // Lgb
602                                         column += 19;
603                                 }
604                                 break;
605                         }
606                         // Typewriter font also has them
607                         if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
608                                 os.put(c);
609                                 break;
610                         }
611                         // Otherwise, we use what LaTeX
612                         // provides us.
613                         switch (c) {
614                         case '<':
615                                 os << "\\textless{}";
616                                 column += 10;
617                                 break;
618                         case '>':
619                                 os << "\\textgreater{}";
620                                 column += 13;
621                                 break;
622                         case '|':
623                                 os << "\\textbar{}";
624                                 column += 9;
625                                 break;
626                         }
627                         break;
628
629                 case '-': // "--" in Typewriter mode -> "-{}-"
630                         if (i <= size() - 2
631                             && getChar(i + 1) == '-'
632                             && font.family() == LyXFont::TYPEWRITER_FAMILY) {
633                                 os << "-{}";
634                                 column += 2;
635                         } else {
636                                 os << '-';
637                         }
638                         break;
639
640                 case '\"':
641                         os << "\\char`\\\"{}";
642                         column += 9;
643                         break;
644
645                 case 0xa3:    // £ POUND SIGN
646                         if (bparams.inputenc == "default") {
647                                 os << "\\pounds{}";
648                                 column += 8;
649                         } else {
650                                 os.put(c);
651                         }
652                         break;
653
654                 case '$': case '&':
655                 case '%': case '#': case '{':
656                 case '}': case '_':
657                         os << '\\';
658                         os.put(c);
659                         column += 1;
660                         break;
661
662                 case '~':
663                         os << "\\textasciitilde{}";
664                         column += 16;
665                         break;
666
667                 case '^':
668                         os << "\\textasciicircum{}";
669                         column += 17;
670                         break;
671
672                 case '*': case '[':
673                         // avoid being mistaken for optional arguments
674                         os << '{';
675                         os.put(c);
676                         os << '}';
677                         column += 2;
678                         break;
679
680                 case ' ':
681                         // Blanks are printed before font switching.
682                         // Sure? I am not! (try nice-latex)
683                         // I am sure it's correct. LyX might be smarter
684                         // in the future, but for now, nothing wrong is
685                         // written. (Asger)
686                         break;
687
688                 default:
689
690                         // I assume this is hack treating typewriter as verbatim
691                         if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
692                                 if (c != '\0') {
693                                         os.put(c);
694                                 }
695                                 break;
696                         }
697
698                         // LyX, LaTeX etc.
699
700                         // FIXME: if we have "LaTeX" with a font
701                         // change in the middle (before the 'T', then
702                         // the "TeX" part is still special cased.
703                         // Really we should only operate this on
704                         // "words" for some definition of word
705
706                         size_t pnr = 0;
707
708                         for (; pnr < phrases_nr; ++pnr) {
709                                 if (isTextAt(special_phrases[pnr].phrase, i)) {
710                                         os << special_phrases[pnr].macro;
711                                         i += special_phrases[pnr].phrase.length() - 1;
712                                         column += special_phrases[pnr].macro.length() - 1;
713                                         break;
714                                 }
715                         }
716
717                         if (pnr == phrases_nr && c != '\0') {
718                                 os.put(c);
719                         }
720                         break;
721                 }
722         }
723 }
724
725
726 void Paragraph::Pimpl::validate(LaTeXFeatures & features,
727                                 LyXLayout const & layout) const
728 {
729         BufferParams const & bparams = features.bufferParams();
730
731         // check the params.
732         if (!params.spacing().isDefault())
733                 features.require("setspace");
734
735         // then the layouts
736         features.useLayout(layout.name());
737
738         // then the fonts
739         Language const * doc_language = bparams.language;
740
741         FontList::const_iterator fcit = fontlist.begin();
742         FontList::const_iterator fend = fontlist.end();
743         for (; fcit != fend; ++fcit) {
744                 if (fcit->font().noun() == LyXFont::ON) {
745                         lyxerr[Debug::LATEX] << "font.noun: "
746                                              << fcit->font().noun()
747                                              << endl;
748                         features.require("noun");
749                         lyxerr[Debug::LATEX] << "Noun enabled. Font: "
750                                              << fcit->font().stateText(0)
751                                              << endl;
752                 }
753                 switch (fcit->font().color()) {
754                 case LColor::none:
755                 case LColor::inherit:
756                 case LColor::ignore:
757                         // probably we should put here all interface colors used for
758                         // font displaying! For now I just add this ones I know of (Jug)
759                 case LColor::latex:
760                 case LColor::note:
761                         break;
762                 default:
763                         features.require("color");
764                         lyxerr[Debug::LATEX] << "Color enabled. Font: "
765                                              << fcit->font().stateText(0)
766                                              << endl;
767                 }
768
769                 Language const * language = fcit->font().language();
770                 if (language->babel() != doc_language->babel() &&
771                     language != ignore_language &&
772                     language != latex_language)
773                 {
774                         features.useLanguage(language);
775                         lyxerr[Debug::LATEX] << "Found language "
776                                              << language->babel() << endl;
777                 }
778         }
779
780         if (!params.leftIndent().zero())
781                 features.require("ParagraphLeftIndent");
782
783         // then the insets
784         InsetList::const_iterator icit = owner_->insetlist.begin();
785         InsetList::const_iterator iend = owner_->insetlist.end();
786         for (; icit != iend; ++icit) {
787                 if (icit->inset) {
788                         icit->inset->validate(features);
789                         if (layout.needprotect &&
790                             icit->inset->lyxCode() == InsetBase::FOOT_CODE)
791                                 features.require("NeedLyXFootnoteCode");
792                 }
793         }
794
795         // then the contents
796         for (pos_type i = 0; i < size() ; ++i) {
797                 for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
798                         if (!special_phrases[pnr].builtin
799                             && isTextAt(special_phrases[pnr].phrase, i)) {
800                                 features.require(special_phrases[pnr].phrase);
801                                 break;
802                         }
803                 }
804         }
805 }
806
807
808 } // namespace lyx