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