1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
20 #include "lyxparagraph.h"
21 #include "support/textutils.h"
24 #include "tex-strings.h"
25 #include "bufferparams.h"
26 #include "support/FileInfo.h"
27 #include "support/LAssert.h"
29 #include "LaTeXFeatures.h"
30 #include "insets/insetinclude.h"
31 #include "insets/insetbib.h"
32 #include "support/filetools.h"
33 #include "lyx_gui_misc.h"
35 #include "support/lyxmanip.h"
41 using std::lower_bound;
42 using std::upper_bound;
45 int tex_code_break_column = 72; // needs non-zero initialization. set later.
46 // this is a bad idea, but how can LyXParagraph find its buffer to get
47 // parameters? (JMarc)
48 extern BufferView * current_view;
52 extern string bibitemWidthest(Painter &);
54 // this is a minibuffer
55 static char minibuffer_char;
56 static LyXFont minibuffer_font;
57 static Inset * minibuffer_inset;
60 // Initialization of the counter for the paragraph id's,
61 // declared in lyxparagraph.h
62 unsigned int LyXParagraph::paragraph_id = 0;
65 LyXParagraph::LyXParagraph()
67 text.reserve(500); // is this number too big?
69 for (int i = 0; i < 10; ++i) setCounter(i , 0);
75 footnoteflag = LyXParagraph::NO_FOOTNOTE;
76 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
78 align = LYX_ALIGN_BLOCK;
80 /* table stuff -- begin*/
82 /* table stuff -- end*/
85 bibkey = 0; // ale970302
90 // This konstruktor inserts the new paragraph in a list.
91 LyXParagraph::LyXParagraph(LyXParagraph * par)
94 par->text.resize(par->text.size());
96 for (int i = 0; i < 10; ++i) setCounter(i, 0);
100 // double linked list begin
103 next->previous = this;
105 previous->next = this;
107 footnoteflag = LyXParagraph::NO_FOOTNOTE;
108 footnotekind = LyXParagraph::FOOTNOTE;
110 /* table stuff -- begin*/
112 /* table stuff -- end*/
114 id_ = paragraph_id++;
116 bibkey = 0; // ale970302
122 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
123 char footflag, char dth) const
125 LyXFont font1, font2;
130 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
132 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
134 // The beginning or the end of a footnote environment?
135 if (footflag != footnoteflag) {
136 footflag = footnoteflag;
138 os << "\n\\begin_float "
139 << string_footnotekinds[footnotekind]
142 os << "\n\\end_float ";
146 // The beginning or end of a deeper (i.e. nested) area?
149 while (depth > dth) {
150 os << "\n\\begin_deeper ";
154 while (depth < dth) {
155 os << "\n\\end_deeper ";
161 // First write the layout
163 << textclasslist.NameOfLayout(params.textclass, layout)
166 // Maybe some vertical spaces.
167 if (added_space_top.kind() != VSpace::NONE)
168 os << "\\added_space_top "
169 << added_space_top.asLyXCommand() << " ";
170 if (added_space_bottom.kind() != VSpace::NONE)
171 os << "\\added_space_bottom "
172 << added_space_bottom.asLyXCommand() << " ";
174 // Maybe the paragraph has special spacing
175 spacing.writeFile(os, true);
177 // The labelwidth string used in lists.
178 if (!labelwidthstring.empty())
179 os << "\\labelwidthstring "
180 << labelwidthstring << '\n';
182 // Lines above or below?
186 os << "\\line_bottom ";
188 // Pagebreaks above or below?
190 os << "\\pagebreak_top ";
191 if (pagebreak_bottom)
192 os << "\\pagebreak_bottom ";
194 // Start of appendix?
195 if (start_of_appendix)
196 os << "\\start_of_appendix ";
203 if (align != LYX_ALIGN_LAYOUT) {
205 case LYX_ALIGN_LEFT: h = 1; break;
206 case LYX_ALIGN_RIGHT: h = 2; break;
207 case LYX_ALIGN_CENTER: h = 3; break;
208 default: h = 0; break;
210 os << "\\align " << string_align[h] << " ";
212 if (pextra_type != PEXTRA_NONE) {
213 os << "\\pextra_type " << pextra_type;
214 if (pextra_type == PEXTRA_MINIPAGE) {
215 os << " \\pextra_alignment "
218 os << " \\pextra_hfill "
220 if (pextra_start_minipage)
221 os << " \\pextra_start_minipage "
222 << pextra_start_minipage;
224 if (!pextra_width.empty()) {
225 os << " \\pextra_width "
226 << VSpace(pextra_width).asLyXCommand();
227 } else if (!pextra_widthp.empty()) {
228 os << " \\pextra_widthp "
234 // Dummy layout. This means that a footnote ended.
235 os << "\n\\end_float ";
236 footflag = LyXParagraph::NO_FOOTNOTE;
239 // It might be a table.
241 os << "\\LyXTable\n";
249 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
252 for (size_type i = 0; i < size(); ++i) {
258 // Write font changes
259 font2 = GetFontSettings(i);
260 if (font2 != font1) {
261 font2.lyxWriteChanges(font1, os);
270 Inset const * inset = GetInset(i);
272 if (inset->DirectWrite()) {
273 // international char, let it write
274 // code directly so it's shorter in
278 os << "\n\\begin_inset ";
280 os << "\n\\end_inset \n\n";
286 os << "\n\\newline \n";
290 os << "\n\\hfill \n";
294 os << "\n\\backslash \n";
298 if (i + 1 < size() && GetChar(i + 1) == ' ') {
305 if ((column > 70 && c == ' ')
310 // this check is to amend a bug. LyX sometimes
311 // inserts '\0' this could cause problems.
315 lyxerr << "ERROR (LyXParagraph::writeFile):"
316 " NULL char in structure." << endl;
322 // now write the next paragraph
324 next->writeFile(os, params, footflag, dth);
328 void LyXParagraph::validate(LaTeXFeatures & features) const
330 BufferParams const & params = features.bufferParams();
332 // this will be useful later
333 LyXLayout const & layout =
334 textclasslist.Style(params.textclass,
338 if (line_top || line_bottom)
339 features.lyxline = true;
340 if (!spacing.isDefault())
341 features.setspace = true;
344 features.layout[GetLayout()] = true;
347 Language const * doc_language = params.language_info;
349 for (FontList::const_iterator cit = fontlist.begin();
350 cit != fontlist.end(); ++cit) {
351 if ((*cit).font.noun() == LyXFont::ON) {
352 lyxerr[Debug::LATEX] << "font.noun: "
353 << (*cit).font.noun()
355 features.noun = true;
356 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
357 << (*cit).font.stateText()
360 switch ((*cit).font.color()) {
362 case LColor::inherit:
366 features.color = true;
367 lyxerr[Debug::LATEX] << "Color enabled. Font: "
368 << (*cit).font.stateText()
372 Language const * language = (*cit).font.language();
373 if (language != doc_language) {
374 features.UsedLanguages.insert(language);
375 lyxerr[Debug::LATEX] << "Found language "
376 << language->lang << endl;
381 // This is not efficient. I plan to use the code above, after I
382 // change the fontlist handling.
383 for (size_type i = 0; i < size(); ++i) {
384 Language const * language = GetFontSettings(i).language();
385 if (language != doc_language)
386 features.UsedLanguages.insert(language);
390 for (InsetList::const_iterator cit = insetlist.begin();
391 cit != insetlist.end(); ++cit) {
393 (*cit).inset->Validate(features);
396 if (table && table->IsLongTable())
397 features.longtable = true;
398 if (pextra_type == PEXTRA_INDENT)
399 features.LyXParagraphIndent = true;
400 if (pextra_type == PEXTRA_FLOATFLT)
401 features.floatflt = true;
402 if (layout.needprotect
403 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
404 features.NeedLyXFootnoteCode = true;
405 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
406 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
407 features.NeedLyXMinipageIndent = true;
408 if (table && table->NeedRotating())
409 features.rotating = true;
410 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
411 features.algorithm = true;
415 // First few functions needed for cut and paste and paragraph breaking.
416 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
418 minibuffer_char = GetChar(pos);
419 minibuffer_font = GetFontSettings(pos);
420 minibuffer_inset = 0;
421 if (minibuffer_char == LyXParagraph::META_INSET) {
423 minibuffer_inset = GetInset(pos)->Clone();
425 minibuffer_inset = 0;
426 minibuffer_char = ' ';
427 // This reflects what GetInset() does (ARRae)
433 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
435 minibuffer_char = GetChar(pos);
436 minibuffer_font = GetFontSettings(pos);
437 minibuffer_inset = 0;
438 if (minibuffer_char == LyXParagraph::META_INSET) {
440 minibuffer_inset = GetInset(pos);
441 // This is a little hack since I want exactly
442 // the inset, not just a clone. Otherwise
443 // the inset would be deleted when calling Erase(pos)
445 InsetList::iterator it = lower_bound(insetlist.begin(),
448 if (it != insetlist.end() && (*it).pos == pos)
451 minibuffer_inset = 0;
452 minibuffer_char = ' ';
453 // This reflects what GetInset() does (ARRae)
458 // Erase(pos); now the caller is responsible for that.
462 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
464 if ((minibuffer_char == LyXParagraph::META_INSET) &&
465 !InsertInsetAllowed(minibuffer_inset))
467 InsertChar(pos, minibuffer_char);
468 SetFont(pos, minibuffer_font);
469 if (minibuffer_char == LyXParagraph::META_INSET)
470 InsertInset(pos, minibuffer_inset);
478 void LyXParagraph::Clear()
483 pagebreak_top = false;
484 pagebreak_bottom = false;
486 added_space_top = VSpace(VSpace::NONE);
487 added_space_bottom = VSpace(VSpace::NONE);
488 spacing.set(Spacing::Default);
490 align = LYX_ALIGN_LAYOUT;
494 pextra_type = PEXTRA_NONE;
495 pextra_width.erase();
496 pextra_widthp.erase();
497 pextra_alignment = MINIPAGE_ALIGN_TOP;
498 pextra_hfill = false;
499 pextra_start_minipage = false;
502 labelwidthstring.erase();
506 start_of_appendix = false;
510 // the destructor removes the new paragraph from the list
511 LyXParagraph::~LyXParagraph()
514 previous->next = next;
516 next->previous = previous;
518 for (InsetList::iterator it = insetlist.begin();
519 it != insetlist.end(); ++it) {
523 /* table stuff -- begin*/
525 /* table stuff -- end*/
530 //lyxerr << "LyXParagraph::paragraph_id = "
531 // << LyXParagraph::paragraph_id << endl;
535 void LyXParagraph::Erase(LyXParagraph::size_type pos)
537 // > because last is the next unused position, and you can
538 // use it if you want
540 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
541 NextAfterFootnote()->Erase(pos - text.size() - 1);
543 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
544 "position does not exist." << endl;
547 if (pos < size()) { // last is free for insertation, but should be empty
548 // if it is an inset, delete the inset entry
549 if (text[pos] == LyXParagraph::META_INSET) {
551 InsetList::iterator it = lower_bound(insetlist.begin(),
554 if (it != insetlist.end() && (*it).pos == pos) {
559 text.erase(text.begin() + pos);
560 // Erase entries in the tables.
561 for (FontList::iterator it = fontlist.begin();
562 it != fontlist.end(); ++it) {
563 if (pos >= (*it).pos && pos <= (*it).pos_end) {
564 if ((*it).pos == (*it).pos_end) {
565 // If it is a multi-character font
566 // entry, we just make it smaller
567 // (see update below), otherwise we
574 // Update all other entries.
575 for (FontList::iterator it = fontlist.begin();
576 it != fontlist.end(); ++it) {
579 if ((*it).pos_end >= pos)
583 // Update the inset table.
584 for (InsetList::iterator it = upper_bound(insetlist.begin(),
587 it != insetlist.end(); ++it)
590 lyxerr << "ERROR (LyXParagraph::Erase): "
591 "can't erase non-existant char." << endl;
596 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
598 // > because last is the next unused position, and you can
599 // use it if you want
602 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
603 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
606 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
607 "position does not exist." << endl;
610 text.insert(text.begin() + pos, c);
611 // Update the font table.
612 for (FontList::iterator it = fontlist.begin();
613 it != fontlist.end(); ++it) {
614 if ((*it).pos >= pos)
616 if ((*it).pos_end >= pos)
620 // Update the inset table.
621 for (InsetList::iterator it = lower_bound(insetlist.begin(),
624 it != insetlist.end(); ++it)
629 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
632 // > because last is the next unused position, and you can
633 // use it if you want
636 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
638 ->InsertInset(pos - text.size() - 1, inset);
640 lyxerr << "ERROR (LyXParagraph::InsertInset): "
641 "position does not exist: " << pos << endl;
644 if (text[pos] != LyXParagraph::META_INSET) {
645 lyxerr << "ERROR (LyXParagraph::InsertInset): "
646 "there is no LyXParagraph::META_INSET" << endl;
651 // Add a new entry in the inset table.
652 InsetList::iterator it = lower_bound(insetlist.begin(),
655 if (it != insetlist.end() && (*it).pos == pos)
656 lyxerr << "ERROR (LyXParagraph::InsertInset): "
657 "there is an inset in position: " << pos << endl;
659 insetlist.insert(it, InsetTable(pos,inset));
661 inset->setOwner(inset_owner);
666 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
669 return inset_owner->InsertInsetAllowed(inset);
674 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
678 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
679 return NextAfterFootnote()
680 ->GetInset(pos - text.size() - 1);
682 lyxerr << "ERROR (LyXParagraph::GetInset): "
683 "position does not exist: "
689 InsetList::iterator it = lower_bound(insetlist.begin(),
692 if (it != insetlist.end() && (*it).pos == pos)
695 lyxerr << "ERROR (LyXParagraph::GetInset): "
696 "Inset does not exist: " << pos << endl;
697 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
698 // Did this commenting out introduce a bug? So far I have not
699 // see any, please enlighten me. (Lgb)
700 // My guess is that since the inset does not exist, we might
701 // as well replace it with a space to prevent craches. (Asger)
706 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
710 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
711 return NextAfterFootnote()
712 ->GetInset(pos - text.size() - 1);
714 lyxerr << "ERROR (LyXParagraph::GetInset): "
715 "position does not exist: "
721 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
724 if (cit != insetlist.end() && (*cit).pos == pos)
727 lyxerr << "ERROR (LyXParagraph::GetInset): "
728 "Inset does not exist: " << pos << endl;
729 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
730 // Did this commenting out introduce a bug? So far I have not
731 // see any, please enlighten me. (Lgb)
732 // My guess is that since the inset does not exist, we might
733 // as well replace it with a space to prevent craches. (Asger)
738 // Gets uninstantiated font setting at position.
739 // Optimized after profiling. (Asger)
740 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
743 #ifdef SORTED_FONT_LIST
744 for (FontList::const_iterator cit = fontlist.begin();
745 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
746 if (pos >= (*cit).pos)
749 for (FontList::const_iterator cit = fontlist.begin();
750 cit != fontlist.end(); ++cit)
751 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
755 // > because last is the next unused position, and you can
756 // use it if you want
757 else if (pos > size()) {
759 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
760 return NextAfterFootnote()
761 ->GetFontSettings(pos - text.size() - 1);
763 // Why is it an error to ask for the font of a
764 // position that does not exist? Would it be
765 // enough for this to be enabled on debug?
766 // We want strict error checking, but it's ok to only
767 // have it when debugging. (Asger)
768 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
769 "position does not exist. "
770 << pos << " (" << static_cast<int>(pos)
773 } else if (pos > 0) {
774 return GetFontSettings(pos - 1);
775 } else // pos = size() = 0
776 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
778 return LyXFont(LyXFont::ALL_INHERIT);
781 // Gets uninstantiated font setting at position 0
782 LyXFont LyXParagraph::GetFirstFontSettings() const
785 #ifdef SORTED_FONT_LIST
786 if (!fontlist.empty() && fontlist.front().pos == 0)
787 return fontlist.front().font;
789 for (FontList::const_iterator cit = fontlist.begin();
790 cit != fontlist.end(); ++cit)
791 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
794 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
795 return NextAfterFootnote()->GetFirstFontSettings();
796 return LyXFont(LyXFont::ALL_INHERIT);
799 // Gets the fully instantiated font at a given position in a paragraph
800 // This is basically the same function as LyXText::GetFont() in text2.C.
801 // The difference is that this one is used for generating the LaTeX file,
802 // and thus cosmetic "improvements" are disallowed: This has to deliver
803 // the true picture of the buffer. (Asger)
804 // If position is -1, we get the layout font of the paragraph.
805 // If position is -2, we get the font of the manual label of the paragraph.
806 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
809 LyXLayout const & layout =
810 textclasslist.Style(current_view->buffer()->params.textclass,
812 LyXParagraph::size_type main_body = 0;
813 if (layout.labeltype == LABEL_MANUAL)
814 main_body = BeginningOfMainBody();
819 layoutfont = layout.labelfont;
821 layoutfont = layout.font;
822 tmpfont = GetFontSettings(pos);
823 tmpfont.realize(layoutfont);
825 // process layoutfont for pos == -1 and labelfont for pos < -1
827 tmpfont = layout.font;
829 tmpfont = layout.labelfont;
830 tmpfont.setLanguage(getParLanguage());
833 // check for environment font information
834 char par_depth = GetDepth();
835 LyXParagraph const * par = this;
836 while (par && par_depth && !tmpfont.resolved()) {
837 par = par->DepthHook(par_depth - 1);
839 tmpfont.realize(textclasslist.
840 Style(current_view->buffer()->params.textclass,
841 par->GetLayout()).font);
842 par_depth = par->GetDepth();
846 tmpfont.realize(textclasslist
847 .TextClass(current_view->buffer()->params.textclass)
853 /// Returns the height of the highest font in range
855 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
856 LyXParagraph::size_type endpos) const
858 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
859 for (FontList::const_iterator cit = fontlist.begin();
860 cit != fontlist.end(); ++cit) {
861 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
862 LyXFont::FONT_SIZE size = (*cit).font.size();
863 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
871 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
878 // > because last is the next unused position, and you can
879 // use it if you want
880 else if (pos > size()) {
881 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
882 return NextAfterFootnote()
883 ->GetChar(pos - text.size() - 1);
885 lyxerr << "ERROR (LyXParagraph::GetChar): "
886 "position does not exist."
887 << pos << " (" << static_cast<int>(pos)
889 // Assert(false); // This triggers sometimes...
894 // We should have a footnote environment.
895 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
896 // Notice that LyX does request the
897 // last char from time to time. (Asger)
898 //lyxerr << "ERROR (LyXParagraph::GetChar): "
899 // "expected footnote." << endl;
902 switch (next->footnotekind) {
903 case LyXParagraph::FOOTNOTE:
904 return LyXParagraph::META_FOOTNOTE;
905 case LyXParagraph::MARGIN:
906 return LyXParagraph::META_MARGIN;
907 case LyXParagraph::FIG:
908 case LyXParagraph::WIDE_FIG:
909 return LyXParagraph::META_FIG;
910 case LyXParagraph::TAB:
911 case LyXParagraph::WIDE_TAB:
912 return LyXParagraph::META_TAB;
913 case LyXParagraph::ALGORITHM:
914 return LyXParagraph::META_ALGORITHM;
916 return '\0'; // to shut up gcc
921 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
928 // > because last is the next unused position, and you can
929 // use it if you want
930 else if (pos > size()) {
931 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
932 return NextAfterFootnote()
933 ->GetChar(pos - text.size() - 1);
935 lyxerr << "ERROR (LyXParagraph::GetChar const): "
936 "position does not exist."
937 << pos << " (" << static_cast<int>(pos)
943 // We should have a footnote environment.
944 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
945 // Notice that LyX does request the
946 // last char from time to time. (Asger)
947 //lyxerr << "ERROR (LyXParagraph::GetChar): "
948 // "expected footnote." << endl;
951 switch (next->footnotekind) {
952 case LyXParagraph::FOOTNOTE:
953 return LyXParagraph::META_FOOTNOTE;
954 case LyXParagraph::MARGIN:
955 return LyXParagraph::META_MARGIN;
956 case LyXParagraph::FIG:
957 case LyXParagraph::WIDE_FIG:
958 return LyXParagraph::META_FIG;
959 case LyXParagraph::TAB:
960 case LyXParagraph::WIDE_TAB:
961 return LyXParagraph::META_TAB;
962 case LyXParagraph::ALGORITHM:
963 return LyXParagraph::META_ALGORITHM;
965 return '\0'; // to shut up gcc
970 // return an string of the current word, and the end of the word in lastpos.
971 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
975 // the current word is defined as starting at the first character
976 // from the immediate left of lastpospos which meets the definition
977 // of IsLetter(), continuing to the last character to the right
978 // of this meeting IsLetter.
984 // move back until we have a letter
986 //there's no real reason to have firstpos & lastpos as
987 //separate variables as this is written, but maybe someon
988 // will want to return firstpos in the future.
990 //since someone might have typed a punctuation first
991 int firstpos = lastpos;
993 while ((firstpos >= 0) && !IsLetter(firstpos))
996 // now find the beginning by looking for a nonletter
998 while ((firstpos>= 0) && IsLetter(firstpos))
1001 // the above is now pointing to the preceeding non-letter
1005 // so copy characters into theword until we get a nonletter
1006 // note that this can easily exceed lastpos, wich means
1007 // that if used in the middle of a word, the whole word
1010 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1017 LyXParagraph::size_type LyXParagraph::Last() const
1019 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1020 return text.size() + NextAfterFootnote()->Last() + 1;
1021 // the 1 is the symbol
1028 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1030 // > because last is the next unused position, and you can
1031 // use it if you want
1034 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1035 return NextAfterFootnote()
1036 ->ParFromPos(pos - text.size() - 1);
1038 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1039 "position does not exist." << endl;
1046 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1048 // > because last is the next unused position, and you can
1049 // use it if you want
1052 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1053 return NextAfterFootnote()
1054 ->PositionInParFromPos(pos - text.size() - 1);
1057 "ERROR (LyXParagraph::PositionInParFromPos): "
1058 "position does not exist." << endl;
1066 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1067 LyXFont const & font)
1069 // > because last is the next unused position, and you can
1070 // use it if you want
1073 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1074 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1077 lyxerr << "ERROR (LyXParagraph::SetFont): "
1078 "position does not exist." << endl;
1082 LyXFont patternfont(LyXFont::ALL_INHERIT);
1084 // First, reduce font against layout/label font
1085 // Update: The SetCharFont() routine in text2.C already
1086 // reduces font, so we don't need to do that here. (Asger)
1087 // No need to simplify this because it will disappear
1088 // in a new kernel. (Asger)
1089 // Next search font table
1090 FontList::iterator tmp = fontlist.begin();
1091 for (; tmp != fontlist.end(); ++tmp) {
1092 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1096 if (tmp == fontlist.end()) { // !found
1097 // if we did not find a font entry, but if the font at hand
1098 // is the same as default, we just forget it
1099 if (font == patternfont) return;
1101 // ok, we did not find a font entry. But maybe there is exactly
1102 // the needed font ientry one position left
1103 FontList::iterator tmp2 = fontlist.begin();
1104 for (; tmp2 != fontlist.end(); ++tmp2) {
1105 if (pos - 1 >= (*tmp2).pos
1106 && pos - 1 <= (*tmp2).pos_end)
1109 if (tmp2 != fontlist.end()) {
1110 // ok there is one, maybe it is exactly
1112 if ((*tmp2).font == font) {
1113 // put the position under the font
1118 // Add a new entry in the
1119 // fontlist for the position
1123 ft.font = font; // or patternfont
1124 // It seems that using font instead of patternfont here
1125 // fixes all the problems. This also surfaces a "bug" in
1127 fontlist.insert(fontlist.begin(), ft);
1128 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1130 // more than one character
1131 if (pos == (*tmp).pos) {
1132 // maybe we should enlarge the left fonttable
1133 FontList::iterator tmp2 = fontlist.begin();
1134 for (; tmp2 != fontlist.end(); ++tmp2) {
1135 if (pos - 1 >= (*tmp2).pos
1136 && pos - 1 <= (*tmp2).pos_end)
1139 // Is there is one, and is it exactly
1141 if (tmp2 != fontlist.end() &&
1142 (*tmp2).font == font) {
1143 // Put the position under the font
1149 // Add a new entry in the
1150 // fontlist for the position
1153 ft.pos_end = (*tmp).pos_end;
1154 ft.font = (*tmp).font;
1155 (*tmp).pos_end = pos;
1157 fontlist.insert(fontlist.begin(), ft);
1158 } else if (pos == (*tmp).pos_end) {
1159 // Add a new entry in the
1160 // fontlist for the position
1162 ft.pos = (*tmp).pos;
1163 ft.pos_end = (*tmp).pos_end - 1;
1164 ft.font = (*tmp).font;
1165 (*tmp).pos = (*tmp).pos_end;
1167 fontlist.insert(fontlist.begin(), ft);
1169 // Add a new entry in the
1170 // fontlist for the position
1172 ft.pos = (*tmp).pos;
1173 ft.pos_end = pos - 1;
1174 ft.font = (*tmp).font;
1178 ft2.pos_end = (*tmp).pos_end;
1179 ft2.font = (*tmp).font;
1182 (*tmp).pos_end = pos;
1185 fontlist.insert(fontlist.begin(), ft);
1186 fontlist.insert(fontlist.begin(), ft2);
1194 // This function is able to hide closed footnotes.
1195 LyXParagraph * LyXParagraph::Next()
1197 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1198 LyXParagraph * tmp = next;
1200 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1202 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1203 return tmp->Next(); /* there can be more than one
1204 footnote in a logical
1207 return next; // This should never happen!
1213 LyXParagraph * LyXParagraph::NextAfterFootnote()
1215 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1216 LyXParagraph * tmp = next;
1217 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1219 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1220 return tmp; /* there can be more than one footnote
1221 in a logical paragraph */
1223 return next; // This should never happen!
1229 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1231 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1232 LyXParagraph * tmp = next;
1233 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1235 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1236 return tmp; /* there can be more than one footnote
1237 in a logical paragraph */
1239 return next; // This should never happen!
1245 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1248 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1250 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1251 tmp = tmp->previous;
1252 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1253 return tmp; /* there can be more than one footnote
1254 in a logical paragraph */
1256 return previous; // This should never happen!
1262 LyXParagraph * LyXParagraph::LastPhysicalPar()
1264 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1267 LyXParagraph * tmp = this;
1269 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1270 tmp = tmp->NextAfterFootnote();
1275 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1277 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1280 LyXParagraph const * tmp = this;
1282 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1283 tmp = tmp->NextAfterFootnote();
1288 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1292 LyXParagraph * tmppar = this;
1296 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1297 tmppar = tmppar->previous;
1306 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1310 LyXParagraph const * tmppar = this;
1314 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1315 tmppar = tmppar->previous;
1324 // This function is able to hide closed footnotes.
1325 LyXParagraph * LyXParagraph::Previous()
1327 LyXParagraph * tmp = previous;
1332 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1333 tmp = tmp->previous;
1335 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1336 tmp = tmp->previous;
1337 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1338 return tmp->next->Previous();
1347 // This function is able to hide closed footnotes.
1348 LyXParagraph const * LyXParagraph::Previous() const
1350 LyXParagraph * tmp = previous;
1355 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1356 tmp = tmp->previous;
1358 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1359 tmp = tmp->previous;
1360 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1361 return tmp->next->Previous();
1370 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1373 size_type i, j, pos_end, pos_first;
1374 // create a new paragraph
1375 LyXParagraph * par = ParFromPos(pos);
1376 LyXParagraph * firstpar = FirstPhysicalPar();
1378 LyXParagraph * tmp = new LyXParagraph(par);
1380 tmp->footnoteflag = footnoteflag;
1381 tmp->footnotekind = footnotekind;
1383 // this is an idea for a more userfriendly layout handling, I will
1384 // see what the users say
1386 // layout stays the same with latex-environments
1388 tmp->SetOnlyLayout(firstpar->layout);
1389 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1392 if (Last() > pos || !Last() || flag == 2) {
1393 tmp->SetOnlyLayout(firstpar->layout);
1394 tmp->align = firstpar->align;
1395 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1397 tmp->line_bottom = firstpar->line_bottom;
1398 firstpar->line_bottom = false;
1399 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1400 firstpar->pagebreak_bottom = false;
1401 tmp->added_space_bottom = firstpar->added_space_bottom;
1402 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1404 tmp->depth = firstpar->depth;
1405 tmp->noindent = firstpar->noindent;
1407 // copy everything behind the break-position
1408 // to the new paragraph
1410 while (ParFromPos(pos_first) != par)
1413 pos_end = pos_first + par->text.size() - 1;
1415 for (i = j = pos; i <= pos_end; ++i) {
1416 par->CutIntoMinibuffer(i - pos_first);
1417 if (tmp->InsertFromMinibuffer(j - pos))
1420 tmp->text.resize(tmp->text.size());
1421 for (i = pos_end; i >= pos; --i)
1422 par->Erase(i - pos_first);
1424 par->text.resize(par->text.size());
1427 // just an idea of me
1429 tmp->line_top = firstpar->line_top;
1430 tmp->pagebreak_top = firstpar->pagebreak_top;
1431 tmp->added_space_top = firstpar->added_space_top;
1432 tmp->bibkey = firstpar->bibkey;
1434 // layout stays the same with latex-environments
1436 firstpar->SetOnlyLayout(tmp->layout);
1437 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1438 firstpar->depth = tmp->depth;
1444 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1446 par = par->FirstPhysicalPar();
1447 footnoteflag = par->footnoteflag;
1448 footnotekind = par->footnotekind;
1450 layout = par->layout;
1451 align = par-> align;
1452 SetLabelWidthString(par->labelwidthstring);
1454 line_bottom = par->line_bottom;
1455 pagebreak_bottom = par->pagebreak_bottom;
1456 added_space_bottom = par->added_space_bottom;
1458 line_top = par->line_top;
1459 pagebreak_top = par->pagebreak_top;
1460 added_space_top = par->added_space_top;
1462 spacing = par->spacing;
1464 pextra_type = par->pextra_type;
1465 pextra_width = par->pextra_width;
1466 pextra_widthp = par->pextra_widthp;
1467 pextra_alignment = par->pextra_alignment;
1468 pextra_hfill = par->pextra_hfill;
1469 pextra_start_minipage = par->pextra_start_minipage;
1471 noindent = par->noindent;
1476 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1478 LyXParagraph * tmppar = this;
1481 && tmppar->previous->footnoteflag ==
1482 LyXParagraph::CLOSED_FOOTNOTE)
1483 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1484 tmppar = tmppar->previous;
1487 return this; // This should never happen!
1493 LyXParagraph * LyXParagraph::Clone() const
1495 // create a new paragraph
1496 LyXParagraph * result = new LyXParagraph;
1498 result->MakeSameLayout(this);
1500 // this is because of the dummy layout of the paragraphs that
1502 result->layout = layout;
1504 /* table stuff -- begin*/
1506 result->table = table->Clone();
1509 /* table stuff -- end*/
1511 result->inset_owner = inset_owner;
1514 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1517 // copy everything behind the break-position to the new paragraph
1519 result->text = text;
1520 result->fontlist = fontlist;
1521 result->insetlist = insetlist;
1522 for (InsetList::iterator it = result->insetlist.begin();
1523 it != result->insetlist.end(); ++it)
1524 (*it).inset = (*it).inset->Clone();
1529 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1531 par = par->FirstPhysicalPar();
1534 par->footnoteflag == footnoteflag &&
1535 par->footnotekind == footnotekind &&
1537 par->layout == layout &&
1539 par->align == align &&
1541 par->line_bottom == line_bottom &&
1542 par->pagebreak_bottom == pagebreak_bottom &&
1543 par->added_space_bottom == added_space_bottom &&
1545 par->line_top == line_top &&
1546 par->pagebreak_top == pagebreak_top &&
1547 par->added_space_top == added_space_top &&
1549 par->spacing == spacing &&
1551 par->pextra_type == pextra_type &&
1552 par->pextra_width == pextra_width &&
1553 par->pextra_widthp == pextra_widthp &&
1554 par->pextra_alignment == pextra_alignment &&
1555 par->pextra_hfill == pextra_hfill &&
1556 par->pextra_start_minipage == pextra_start_minipage &&
1558 par->table == table && // what means: NO TABLE AT ALL
1560 par->noindent == noindent &&
1561 par->depth == depth);
1565 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1567 // create a new paragraph
1568 LyXParagraph * par = ParFromPos(pos);
1570 LyXParagraph * tmp = new LyXParagraph(par);
1572 tmp->MakeSameLayout(par);
1574 // When can pos < Last()?
1575 // I guess pos == Last() is possible.
1577 // copy everything behind the break-position to the new
1579 size_type pos_first = 0;
1580 while (ParFromPos(pos_first) != par)
1582 size_type pos_end = pos_first + par->text.size() - 1;
1585 for (i = j = pos; i <= pos_end; ++i) {
1586 par->CutIntoMinibuffer(i - pos_first);
1587 if (tmp->InsertFromMinibuffer(j - pos))
1590 tmp->text.resize(tmp->text.size());
1591 for (size_type i = pos_end; i >= pos; --i)
1592 par->Erase(i - pos_first);
1594 par->text.resize(par->text.size());
1599 // Be carefull, this does not make any check at all.
1600 void LyXParagraph::PasteParagraph()
1602 // copy the next paragraph to this one
1603 LyXParagraph * the_next = Next();
1605 LyXParagraph * firstpar = FirstPhysicalPar();
1607 // first the DTP-stuff
1608 firstpar->line_bottom = the_next->line_bottom;
1609 firstpar->added_space_bottom = the_next->added_space_bottom;
1610 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1612 size_type pos_end = the_next->text.size() - 1;
1613 size_type pos_insert = Last();
1615 // ok, now copy the paragraph
1617 for (i = j = 0; i <= pos_end; ++i) {
1618 the_next->CutIntoMinibuffer(i);
1619 if (InsertFromMinibuffer(pos_insert + j))
1623 // delete the next paragraph
1624 LyXParagraph *ppar = the_next->previous;
1625 LyXParagraph *npar = the_next->next;
1631 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1633 LyXParagraph * par = ParFromPos(pos);
1635 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1636 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1642 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1644 LyXParagraph * par = ParFromPos(pos);
1646 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1647 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1652 int LyXParagraph::GetEndLabel() const
1654 LyXParagraph const * par = this;
1655 int par_depth = GetDepth();
1657 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1659 textclasslist.Style(current_view->buffer()->params.textclass,
1660 layout).endlabeltype;
1661 if (endlabeltype != END_LABEL_NO_LABEL) {
1662 LyXParagraph const * last = this;
1663 if( footnoteflag == NO_FOOTNOTE)
1664 last = LastPhysicalPar();
1665 else if (next->footnoteflag == NO_FOOTNOTE)
1666 return endlabeltype;
1668 if (!last || !last->next)
1669 return endlabeltype;
1671 int next_depth = last->next->GetDepth();
1672 if (par_depth > next_depth ||
1673 (par_depth == next_depth && layout != last->next->GetLayout() ))
1674 return endlabeltype;
1679 par = par->DepthHook(par_depth - 1);
1681 par_depth = par->GetDepth();
1683 return END_LABEL_NO_LABEL;
1687 LyXTextClass::size_type LyXParagraph::GetLayout() const
1689 return FirstPhysicalPar()->layout;
1693 char LyXParagraph::GetDepth() const
1695 return FirstPhysicalPar()->depth;
1699 char LyXParagraph::GetAlign() const
1701 return FirstPhysicalPar()->align;
1705 string LyXParagraph::GetLabelstring() const
1707 return FirstPhysicalPar()->labelstring;
1711 int LyXParagraph::GetFirstCounter(int i) const
1713 return FirstPhysicalPar()->counter_[i];
1717 // the next two functions are for the manual labels
1718 string LyXParagraph::GetLabelWidthString() const
1720 if (!FirstPhysicalPar()->labelwidthstring.empty())
1721 return FirstPhysicalPar()->labelwidthstring;
1723 return _("Senseless with this layout!");
1727 void LyXParagraph::SetLabelWidthString(string const & s)
1729 LyXParagraph * par = FirstPhysicalPar();
1731 par->labelwidthstring = s;
1735 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1737 LyXParagraph * par = FirstPhysicalPar();
1738 LyXParagraph * ppar = 0;
1739 LyXParagraph * npar = 0;
1741 par->layout = new_layout;
1742 /* table stuff -- begin*/
1745 /* table stuff -- end*/
1746 if (par->pextra_type == PEXTRA_NONE) {
1747 if (par->Previous()) {
1748 ppar = par->Previous()->FirstPhysicalPar();
1751 && (ppar->depth > par->depth))
1752 ppar = ppar->Previous()->FirstPhysicalPar();
1755 npar = par->Next()->NextAfterFootnote();
1758 && (npar->depth > par->depth))
1759 npar = npar->Next()->NextAfterFootnote();
1761 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1763 p1 = ppar->pextra_width,
1764 p2 = ppar->pextra_widthp;
1765 ppar->SetPExtraType(ppar->pextra_type,
1766 p1.c_str(), p2.c_str());
1768 if ((par->pextra_type == PEXTRA_NONE) &&
1769 npar && (npar->pextra_type != PEXTRA_NONE)) {
1771 p1 = npar->pextra_width,
1772 p2 = npar->pextra_widthp;
1773 npar->SetPExtraType(npar->pextra_type,
1774 p1.c_str(), p2.c_str());
1780 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1783 * par = FirstPhysicalPar(),
1787 par->layout = new_layout;
1788 par->labelwidthstring.erase();
1789 par->align = LYX_ALIGN_LAYOUT;
1790 par->added_space_top = VSpace(VSpace::NONE);
1791 par->added_space_bottom = VSpace(VSpace::NONE);
1792 par->spacing.set(Spacing::Default);
1794 /* table stuff -- begin*/
1797 /* table stuff -- end*/
1798 if (par->pextra_type == PEXTRA_NONE) {
1799 if (par->Previous()) {
1800 ppar = par->Previous()->FirstPhysicalPar();
1803 && (ppar->depth > par->depth))
1804 ppar = ppar->Previous()->FirstPhysicalPar();
1807 npar = par->Next()->NextAfterFootnote();
1810 && (npar->depth > par->depth))
1811 npar = npar->Next()->NextAfterFootnote();
1813 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1815 p1 = ppar->pextra_width,
1816 p2 = ppar->pextra_widthp;
1817 ppar->SetPExtraType(ppar->pextra_type,
1818 p1.c_str(), p2.c_str());
1820 if ((par->pextra_type == PEXTRA_NONE) &&
1821 npar && (npar->pextra_type != PEXTRA_NONE)) {
1823 p1 = npar->pextra_width,
1824 p2 = npar->pextra_widthp;
1825 npar->SetPExtraType(npar->pextra_type,
1826 p1.c_str(), p2.c_str());
1832 // if the layout of a paragraph contains a manual label, the beginning of the
1833 // main body is the beginning of the second word. This is what the par-
1834 // function returns. If the layout does not contain a label, the main
1835 // body always starts with position 0. This differentiation is necessary,
1836 // because there cannot be a newline or a blank <= the beginning of the
1837 // main body in TeX.
1839 int LyXParagraph::BeginningOfMainBody() const
1841 if (FirstPhysicalPar() != this)
1844 // Unroll the first two cycles of the loop
1845 // and remember the previous character to
1846 // remove unnecessary GetChar() calls
1849 && GetChar(i) != LyXParagraph::META_NEWLINE
1852 char previous_char = 0, temp = 0;
1854 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1855 // Yes, this ^ is supposed to be "= " not "=="
1858 && previous_char != ' '
1859 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1861 previous_char = temp;
1866 if (i == 0 && i == size() &&
1867 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1868 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1869 ++i; /* the cursor should not jump
1870 * to the main body if there
1876 LyXParagraph * LyXParagraph::DepthHook(int deth)
1878 LyXParagraph * newpar = this;
1883 newpar = newpar->FirstPhysicalPar()->Previous();
1884 } while (newpar && newpar->GetDepth() > deth
1885 && newpar->footnoteflag == footnoteflag);
1888 if (Previous() || GetDepth())
1889 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1893 return newpar->FirstPhysicalPar();
1897 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1899 LyXParagraph const * newpar = this;
1904 newpar = newpar->FirstPhysicalPar()->Previous();
1905 } while (newpar && newpar->GetDepth() > deth
1906 && newpar->footnoteflag == footnoteflag);
1909 if (Previous() || GetDepth())
1910 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1914 return newpar->FirstPhysicalPar();
1918 int LyXParagraph::AutoDeleteInsets()
1921 InsetList::size_type index = 0;
1922 while (index < insetlist.size()) {
1923 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1924 Erase(insetlist[index].pos);
1925 // Erase() calls to insetlist.erase(&insetlist[index])
1926 // so index shouldn't be increased.
1935 LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
1937 InsetList::iterator it = lower_bound(insetlist.begin(),
1940 return inset_iterator(it);
1944 // returns -1 if inset not found
1945 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1948 // We could use lower_bound here too, we just need to add
1949 // the approp. operator() to matchIT (and change the name
1950 // of that struct). Code would then be:
1951 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1953 // inset, matchIT());
1954 // if ((*cit).inset == inset) {
1955 // return (*cit).pos;
1957 for (InsetList::const_iterator cit = insetlist.begin();
1958 cit != insetlist.end(); ++cit) {
1959 if ((*cit).inset == inset) {
1963 // Think about footnotes.
1964 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1965 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1967 NextAfterFootnote()->GetPositionOfInset(inset);
1969 return text.size() + 1 + further;
1975 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1978 TexRow & foot_texrow,
1981 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1982 LyXLayout const & style =
1983 textclasslist.Style(current_view->buffer()->params.textclass,
1986 bool further_blank_line = false;
1988 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1990 if (start_of_appendix) {
1991 os << "\\appendix\n";
1995 if (!spacing.isDefault()
1996 && (!Previous() || !Previous()->HasSameLayout(this))) {
1997 os << spacing.writeEnvirBegin() << "\n";
2001 if (tex_code_break_column && style.isCommand()){
2006 if (pagebreak_top) {
2008 further_blank_line = true;
2010 if (added_space_top.kind() != VSpace::NONE) {
2011 os << added_space_top.asLatexCommand(current_view->buffer()->params);
2012 further_blank_line = true;
2016 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2017 << "\\vspace{-1\\parskip}";
2018 further_blank_line = true;
2021 if (further_blank_line){
2026 Language const * language = getParLanguage();
2027 Language const * doc_language = current_view->buffer()->params.language_info;
2028 if (language != doc_language) {
2029 os << subst(lyxrc.language_command_begin, "$$lang",
2035 switch (style.latextype) {
2038 << style.latexname()
2039 << style.latexparam();
2041 case LATEX_ITEM_ENVIRONMENT:
2043 bibkey->Latex(os, false, false);
2047 case LATEX_LIST_ENVIRONMENT:
2054 bool need_par = SimpleTeXOnePar(os, texrow, moving_arg);
2056 // Spit out footnotes
2057 LyXParagraph * par = next;
2058 if (lyxrc.rtl_support) {
2059 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2060 && next->footnoteflag != footnoteflag) {
2061 LyXParagraph * p = 0;
2062 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2063 if ( (p = NextAfterFootnote()) != 0 &&
2064 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2065 is_rtl = GetFontSettings(0).isRightToLeft();
2067 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2068 par->footnoteflag != footnoteflag) {
2069 par = par->TeXFootnote(os, texrow, foot,
2070 foot_texrow, foot_count,
2072 par->SimpleTeXOnePar(os, texrow, moving_arg);
2073 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2075 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2076 (p = par->NextAfterFootnote()) != 0 &&
2077 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2078 is_rtl = GetFontSettings(0).isRightToLeft();
2083 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2084 && par->footnoteflag != footnoteflag) {
2085 par = par->TeXFootnote(os, texrow,
2086 foot, foot_texrow, foot_count,
2088 par->SimpleTeXOnePar(os, texrow, moving_arg);
2093 // Make sure that \\par is done with the font of the last
2094 // character if this has another size as the default.
2095 // This is necessary because LaTeX (and LyX on the screen)
2096 // calculates the space between the baselines according
2097 // to this font. (Matthias)
2098 LyXFont font = getFont(Last() - 1);
2100 if (style.resfont.size() != font.size()) {
2106 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2107 GetLayout()).isCommand()){
2108 if (style.resfont.size() != font.size()) {
2114 } else if (style.resfont.size() != font.size()){
2115 os << "{\\" << font.latexSize() << " \\par}";
2118 if (language != doc_language) {
2120 << subst(lyxrc.language_command_end, "$$lang",
2121 doc_language->lang);
2124 switch (style.latextype) {
2125 case LATEX_ITEM_ENVIRONMENT:
2126 case LATEX_LIST_ENVIRONMENT:
2127 if (par && (depth < par->depth)) {
2132 case LATEX_ENVIRONMENT:
2133 // if its the last paragraph of the current environment
2134 // skip it otherwise fall through
2136 && (par->layout != layout
2137 || par->depth != depth
2138 || par->pextra_type != pextra_type))
2141 // we don't need it for the last paragraph!!!
2142 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2143 && footnotekind != LyXParagraph::FOOTNOTE
2144 && footnotekind != LyXParagraph::MARGIN
2148 // don't insert this if we would be adding it
2149 // before or after a table in a float. This
2150 // little trick is needed in order to allow
2151 // use of tables in \subfigures or \subtables.
2157 further_blank_line = false;
2159 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2160 further_blank_line = true;
2163 if (added_space_bottom.kind() != VSpace::NONE) {
2164 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2165 further_blank_line = true;
2168 if (pagebreak_bottom) {
2170 further_blank_line = true;
2173 if (further_blank_line){
2178 if (!spacing.isDefault()
2179 && (!par || !par->HasSameLayout(this))) {
2180 os << spacing.writeEnvirEnd() << "\n";
2184 // we don't need it for the last paragraph!!!
2185 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2186 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2191 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2196 // This one spits out the text of the paragraph
2197 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow,
2200 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2203 return SimpleTeXOneTablePar(os, texrow);
2205 bool return_value = false;
2207 LyXLayout const & style =
2208 textclasslist.Style(current_view->buffer()->params.textclass,
2210 LyXFont basefont, last_font;
2212 // Maybe we have to create a optional argument.
2213 size_type main_body;
2214 if (style.labeltype != LABEL_MANUAL)
2217 main_body = BeginningOfMainBody();
2219 if (main_body > 0) {
2221 basefont = getFont(-2); // Get label font
2223 basefont = getFont(-1); // Get layout font
2231 if (style.isCommand()) {
2234 } else if (align != LYX_ALIGN_LAYOUT) {
2237 return_value = true;
2241 moving_arg |= style.needprotect;
2243 // Which font is currently active?
2244 LyXFont running_font(basefont);
2245 // Do we have an open font change?
2246 bool open_font = false;
2248 texrow.start(this, 0);
2250 for (size_type i = 0; i < size(); ++i) {
2252 // First char in paragraph or after label?
2253 if (i == main_body && !IsDummy()) {
2254 if (main_body > 0) {
2256 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2259 basefont = getFont(-1); // Now use the layout font
2260 running_font = basefont;
2264 if (style.isCommand()) {
2267 } else if (align != LYX_ALIGN_LAYOUT) {
2270 return_value = true;
2274 os << "\\noindent ";
2278 case LYX_ALIGN_NONE:
2279 case LYX_ALIGN_BLOCK:
2280 case LYX_ALIGN_LAYOUT:
2281 case LYX_ALIGN_SPECIAL:
2283 case LYX_ALIGN_LEFT:
2284 if (getParLanguage()->lang != "hebrew") {
2285 os << "\\raggedright ";
2288 os << "\\raggedleft ";
2292 case LYX_ALIGN_RIGHT:
2293 if (getParLanguage()->lang != "hebrew") {
2294 os << "\\raggedleft ";
2297 os << "\\raggedright ";
2301 case LYX_ALIGN_CENTER:
2302 os << "\\centering ";
2310 // Fully instantiated font
2311 LyXFont font = getFont(i);
2312 LyXParagraph * p = 0;
2313 if (i == 0 && previous &&
2314 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2315 (p = PreviousBeforeFootnote()) != 0)
2316 last_font = p->getFont(p->size()-1);
2318 last_font = running_font;
2320 // Spaces at end of font change are simulated to be
2321 // outside font change, i.e. we write "\textXX{text} "
2322 // rather than "\textXX{text }". (Asger)
2323 if (open_font && c == ' ' && i <= size() - 2
2324 && !getFont(i+1).equalExceptLatex(running_font)
2325 && !getFont(i+1).equalExceptLatex(font)) {
2326 font = getFont(i + 1);
2328 // We end font definition before blanks
2329 if (!font.equalExceptLatex(running_font) && open_font) {
2330 column += running_font.latexWriteEndChanges(os,
2332 (i == main_body-1) ? basefont : font);
2333 running_font = basefont;
2337 // Blanks are printed before start of fontswitch
2339 // Do not print the separation of the optional argument
2340 if (i != main_body - 1) {
2341 SimpleTeXBlanks(os, texrow, i,
2342 column, font, style);
2346 // Do we need to change font?
2347 if (!font.equalExceptLatex(running_font)
2348 && i != main_body-1) {
2349 column += font.latexWriteStartChanges(os, basefont,
2351 running_font = font;
2355 if (c == LyXParagraph::META_NEWLINE) {
2356 // newlines are handled differently here than
2357 // the default in SimpleTeXSpecialChars().
2358 if (!style.newline_allowed
2359 || font.latex() == LyXFont::ON) {
2363 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2366 basefont = getFont(-1);
2367 running_font = basefont;
2368 if (font.family() ==
2369 LyXFont::TYPEWRITER_FAMILY) {
2377 texrow.start(this, i + 1);
2380 SimpleTeXSpecialChars(os, texrow, moving_arg,
2381 font, running_font, basefont,
2382 open_font, style, i, column, c);
2386 // If we have an open font definition, we have to close it
2388 LyXParagraph * p = 0;
2389 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2390 && (p = NextAfterFootnote()) != 0)
2391 running_font.latexWriteEndChanges(os, basefont,
2394 running_font.latexWriteEndChanges(os, basefont, basefont);
2397 // Needed if there is an optional argument but no contents.
2398 if (main_body > 0 && main_body == size()) {
2400 return_value = false;
2403 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2404 return return_value;
2408 // This one spits out the text of a table paragraph
2409 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2411 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2413 bool return_value = false;
2415 LyXLayout const & style =
2416 textclasslist.Style(current_view->buffer()->params.textclass,
2420 if (!IsDummy()) { // it is dummy if it is in a float!!!
2421 if (style.isCommand()) {
2424 } else if (align != LYX_ALIGN_LAYOUT) {
2427 return_value = true;
2430 os << "\\noindent ";
2434 case LYX_ALIGN_NONE:
2435 case LYX_ALIGN_BLOCK:
2436 case LYX_ALIGN_LAYOUT:
2437 case LYX_ALIGN_SPECIAL: break;
2438 case LYX_ALIGN_LEFT:
2439 os << "\\raggedright ";
2442 case LYX_ALIGN_RIGHT:
2443 os << "\\raggedleft ";
2446 case LYX_ALIGN_CENTER:
2447 os << "\\centering ";
2453 LyXFont basefont = getFont(-1); // Get layout font
2454 // Which font is currently active?
2455 LyXFont running_font = basefont;
2457 // Do we have an open font change?
2458 bool open_font = false;
2459 int current_cell_number = -1;
2460 int tmp = table->TexEndOfCell(os, current_cell_number);
2461 for (; tmp > 0 ; --tmp)
2464 texrow.start(this, 0);
2466 bool is_rtl = getParLanguage()->RightToLeft;
2467 bool first_in_cell = true;
2469 for (size_type i = 0; i < size(); ++i) {
2470 char c = GetChar(i);
2471 if (table->IsContRow(current_cell_number + 1)) {
2472 if (c == LyXParagraph::META_NEWLINE)
2473 ++current_cell_number;
2478 if (first_in_cell && is_rtl) {
2481 first_in_cell = false;
2484 // Fully instantiated font
2485 LyXFont font = getFont(i);
2486 last_font = running_font;
2488 // Spaces at end of font change are simulated to be
2489 // outside font change.
2490 // i.e. we write "\textXX{text} " rather than
2491 // "\textXX{text }". (Asger)
2492 if (open_font && c == ' ' && i <= size() - 2
2493 && getFont(i + 1) != running_font
2494 && getFont(i + 1) != font) {
2495 font = getFont(i + 1);
2498 // We end font definition before blanks
2499 if (font != running_font && open_font) {
2500 column += running_font.latexWriteEndChanges(os,
2503 running_font = basefont;
2506 // Blanks are printed before start of fontswitch
2508 SimpleTeXBlanks(os, texrow, i, column, font, style);
2510 // Do we need to change font?
2511 if (font != running_font) {
2512 column += font.latexWriteStartChanges(os, basefont,
2514 running_font = font;
2517 // Do we need to turn on LaTeX mode?
2518 if (font.latex() != running_font.latex()) {
2519 if (font.latex() == LyXFont::ON
2520 && style.needprotect) {
2525 if (c == LyXParagraph::META_NEWLINE) {
2526 // special case for inside a table
2527 // different from default case in
2528 // SimpleTeXSpecialChars()
2530 column += running_font
2531 .latexWriteEndChanges(os, basefont,
2535 basefont = getFont(-1);
2536 running_font = basefont;
2537 ++current_cell_number;
2538 if (table->CellHasContRow(current_cell_number) >= 0) {
2539 TeXContTableRows(os, i + 1,
2540 current_cell_number,
2543 if (is_rtl && !first_in_cell) {
2545 first_in_cell = true;
2548 // if this cell follow only ContRows till end don't
2549 // put the EndOfCell because it is put after the
2551 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2552 --current_cell_number;
2555 int tmp = table->TexEndOfCell(os,
2556 current_cell_number);
2559 } else if (tmp < 0) {
2565 texrow.start(this, i + 1);
2567 SimpleTeXSpecialChars(os, texrow, false,
2568 font, running_font, basefont,
2569 open_font, style, i, column, c);
2573 // If we have an open font definition, we have to close it
2575 running_font.latexWriteEndChanges(os, basefont, basefont);
2577 ++current_cell_number;
2578 if (is_rtl && !first_in_cell)
2580 tmp = table->TexEndOfCell(os, current_cell_number);
2581 for (; tmp > 0; --tmp)
2583 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2584 return return_value;
2588 // This one spits out the text off ContRows in tables
2589 bool LyXParagraph::TeXContTableRows(ostream & os,
2590 LyXParagraph::size_type i,
2591 int current_cell_number,
2592 int & column, TexRow & texrow)
2594 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2600 bool return_value = false;
2601 LyXLayout const & style =
2602 textclasslist.Style(current_view->buffer()->params.textclass,
2604 LyXFont basefont = getFont(-1); // Get layout font
2606 // Which font is currently active?
2607 LyXFont running_font = basefont;
2608 // Do we have an open font change?
2609 bool open_font = false;
2611 size_type lastpos = i;
2612 int cell = table->CellHasContRow(current_cell_number);
2613 ++current_cell_number;
2615 // first find the right position
2617 for (; (i < size()) && (current_cell_number<cell); ++i) {
2619 if (c == LyXParagraph::META_NEWLINE)
2620 ++current_cell_number;
2624 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2628 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2633 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2637 // Fully instantiated font
2638 LyXFont font = getFont(i);
2639 last_font = running_font;
2641 // Spaces at end of font change are simulated to
2642 // be outside font change. i.e. we write
2643 // "\textXX{text} " rather than "\textXX{text }".
2645 if (open_font && c == ' ' && i <= size() - 2
2646 && getFont(i + 1) != running_font
2647 && getFont(i + 1) != font) {
2648 font = getFont(i + 1);
2651 // We end font definition before blanks
2652 if (font != running_font && open_font) {
2653 column += running_font.latexWriteEndChanges(os, basefont, font);
2654 running_font = basefont;
2657 // Blanks are printed before start of fontswitch
2659 SimpleTeXBlanks(os, texrow, i,
2660 column, font, style);
2662 // Do we need to change font?
2663 if (font != running_font) {
2665 font.latexWriteStartChanges(os,
2668 running_font = font;
2671 // Do we need to turn on LaTeX mode?
2672 if (font.latex() != running_font.latex()) {
2673 if (font.latex() == LyXFont::ON
2674 && style.needprotect) {
2679 SimpleTeXSpecialChars(os, texrow, false, font,
2680 running_font, basefont,
2681 open_font, style, i, column, c);
2683 // If we have an open font definition, we have to close it
2685 running_font.latexWriteEndChanges(os, basefont,
2689 basefont = getFont(-1);
2690 running_font = basefont;
2691 cell = table->CellHasContRow(current_cell_number);
2693 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2694 return return_value;
2698 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2700 bool retval = false;
2702 case LyXParagraph::META_HFILL:
2703 sgml_string.erase();
2705 case LyXParagraph::META_NEWLINE:
2709 sgml_string = "&";
2712 sgml_string = "<";
2715 sgml_string = ">";
2718 sgml_string = "$";
2721 sgml_string = "#";
2724 sgml_string = "%";
2727 sgml_string = "[";
2730 sgml_string = "]";
2733 sgml_string = "{";
2736 sgml_string = "}";
2739 sgml_string = "˜";
2742 sgml_string = """;
2745 sgml_string = "\";
2751 case '\0': // Ignore :-)
2752 sgml_string.erase();
2762 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2763 int & desc_on, int depth)
2766 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2768 LyXFont font1, font2;
2771 size_type main_body;
2772 bool emph_flag = false;
2774 LyXLayout const & style =
2775 textclasslist.Style(current_view->buffer()->params.textclass,
2778 if (style.labeltype != LABEL_MANUAL)
2781 main_body = BeginningOfMainBody();
2783 // Gets paragraph main font.
2785 font1 = style.labelfont;
2789 int char_line_count = depth;
2790 os << newlineAndDepth(depth);
2791 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2792 os << "<INFORMALTABLE>"
2793 << newlineAndDepth(++depth);
2795 int current_cell_number = -1;
2796 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2798 // Parsing main loop.
2799 for (size_type i = 0; i < size(); ++i) {
2801 if (table->IsContRow(current_cell_number+1)) {
2802 if (c == LyXParagraph::META_NEWLINE)
2803 ++current_cell_number;
2808 // Fully instantiated font
2811 // Handle <emphasis> tag.
2812 if (font1.emph() != font2.emph() && i) {
2813 if (font2.emph() == LyXFont::ON) {
2816 } else if (emph_flag) {
2817 os << "</emphasis>";
2821 if (c == LyXParagraph::META_NEWLINE) {
2822 // We have only to control for emphasis open here!
2824 os << "</emphasis>";
2827 font1 = font2 = getFont(-1);
2828 ++current_cell_number;
2829 if (table->CellHasContRow(current_cell_number) >= 0) {
2830 DocBookContTableRows(os, extra, desc_on, i + 1,
2831 current_cell_number,
2834 // if this cell follow only ContRows till end don't
2835 // put the EndOfCell because it is put after the
2837 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2838 --current_cell_number;
2841 tmp = table->DocBookEndOfCell(os,
2842 current_cell_number,
2847 } else if (c == LyXParagraph::META_INSET) {
2848 inset = GetInset(i);
2850 std::ostringstream ost;
2851 inset->DocBook(ost);
2852 string tmp_out = ost.str().c_str();
2855 inset->DocBook(ost);
2857 char * ctmp = ost.str();
2858 string tmp_out(ctmp);
2862 // This code needs some explanation:
2863 // Two insets are treated specially
2864 // label if it is the first element in a
2865 // command paragraph
2867 // graphics inside tables or figure floats
2869 // title (the equivalente in latex for this
2871 // and title should come first
2874 if(desc_on != 3 || i != 0) {
2875 if(tmp_out[0] == '@') {
2877 extra += frontStrip(tmp_out,
2880 os << frontStrip(tmp_out,
2885 } else if (font2.latex() == LyXFont::ON) {
2886 // "TeX"-Mode on == > SGML-Mode on.
2892 if (linuxDocConvertChar(c, sgml_string)
2893 && !style.free_spacing) {
2894 // in freespacing mode, spaces are
2895 // non-breaking characters
2900 << "</term><listitem><para>";
2912 // Needed if there is an optional argument but no contents.
2913 if (main_body > 0 && main_body == size()) {
2918 os << "</emphasis>";
2921 ++current_cell_number;
2922 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2923 // Resets description flag correctly.
2926 // <term> not closed...
2930 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2931 os << "</INFORMALTABLE>";
2933 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2938 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2940 LyXParagraph::size_type i,
2941 int current_cell_number, int &column)
2946 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2951 //string emph = "emphasis";
2952 bool emph_flag = false;
2953 int char_line_count = 0;
2955 LyXLayout const & style =
2956 textclasslist.Style(current_view->buffer()->params.textclass,
2959 size_type main_body;
2960 if (style.labeltype != LABEL_MANUAL)
2963 main_body = BeginningOfMainBody();
2965 // Gets paragraph main font.
2968 font1 = style.labelfont;
2972 size_type lastpos = i;
2973 int cell = table->CellHasContRow(current_cell_number);
2974 ++current_cell_number;
2976 // first find the right position
2978 for (; i < size() && current_cell_number < cell; ++i) {
2980 if (c == LyXParagraph::META_NEWLINE)
2981 ++current_cell_number;
2985 // I don't know how to handle this so I comment it
2986 // for the moment (Jug)
2987 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2988 // file += " \\\\\n";
2991 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2996 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3000 // Fully instantiated font
3003 // Handle <emphasis> tag.
3004 if (font1.emph() != font2.emph() && i) {
3005 if (font2.emph() == LyXFont::ON) {
3008 } else if (emph_flag) {
3009 os << "</emphasis>";
3013 if (c == LyXParagraph::META_INSET) {
3014 inset = GetInset(i);
3016 std::ostringstream ost;
3017 inset->DocBook(ost);
3018 string tmp_out = ost.str().c_str();
3021 inset->DocBook(ost);
3023 char * ctmp = ost.str();
3024 string tmp_out(ctmp);
3028 // This code needs some explanation:
3029 // Two insets are treated specially
3030 // label if it is the first element in a
3031 // command paragraph
3033 // graphics inside tables or figure floats
3034 // can't go on title (the equivalente in
3035 // latex for this case is caption and title
3036 // should come first
3039 if(desc_on != 3 || i != 0) {
3040 if(tmp_out[0] == '@') {
3042 extra += frontStrip(tmp_out, '@');
3044 os << frontStrip(tmp_out, '@');
3048 } else if (font2.latex() == LyXFont::ON) {
3049 // "TeX"-Mode on == > SGML-Mode on.
3055 if (linuxDocConvertChar(c, sgml_string)
3056 && !style.free_spacing) {
3057 // in freespacing mode, spaces are
3058 // non-breaking characters
3063 << "</term><listitem><para>";
3073 // we have only to control for emphasis open here!
3075 os << "</emphasis>";
3078 font1 = font2 = getFont(-1);
3079 cell = table->CellHasContRow(current_cell_number);
3081 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3085 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3086 LyXParagraph::size_type const i,
3087 int & column, LyXFont const & font,
3088 LyXLayout const & style)
3090 if (column > tex_code_break_column
3092 && GetChar(i - 1) != ' '
3094 // In LaTeX mode, we don't want to
3095 // break lines since some commands
3097 && ! (font.latex() == LyXFont::ON)
3098 // same in FreeSpacing mode
3099 && !style.free_spacing
3100 // In typewriter mode, we want to avoid
3101 // ! . ? : at the end of a line
3102 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3103 && (GetChar(i-1) == '.'
3104 || GetChar(i-1) == '?'
3105 || GetChar(i-1) == ':'
3106 || GetChar(i-1) == '!'))) {
3107 if (tex_code_break_column == 0) {
3108 // in batchmode we need LaTeX to still
3109 // see it as a space not as an extra '\n'
3115 texrow.start(this, i + 1);
3117 } else if (font.latex() == LyXFont::OFF) {
3118 if (style.free_spacing) {
3127 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3130 LyXFont & running_font,
3133 LyXLayout const & style,
3134 LyXParagraph::size_type & i,
3135 int & column, char const c)
3137 // Two major modes: LaTeX or plain
3138 // Handle here those cases common to both modes
3139 // and then split to handle the two modes separately.
3141 case LyXParagraph::META_INSET: {
3142 Inset * inset = GetInset(i);
3145 int len = os.tellp();
3146 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3147 || inset->LyxCode() == Inset::MATH_CODE
3148 || inset->LyxCode() == Inset::URL_CODE)
3149 && running_font.isRightToLeft()) {
3154 int tmp = inset->Latex(os, moving_arg,
3155 style.free_spacing);
3163 column += os.tellp() - len;
3172 case LyXParagraph::META_NEWLINE:
3174 column += running_font.latexWriteEndChanges(os,
3179 basefont = getFont(-1);
3180 running_font = basefont;
3183 case LyXParagraph::META_HFILL:
3189 // And now for the special cases within each mode
3190 // Are we in LaTeX mode?
3191 if (font.latex() == LyXFont::ON) {
3192 // at present we only have one option
3193 // but I'll leave it as a switch statement
3194 // so its simpler to extend. (ARRae)
3197 // make sure that we will not print
3198 // error generating chars to the tex
3199 // file. This test would not be needed
3200 // if it were done in the buffer
3208 // Plain mode (i.e. not LaTeX)
3211 os << "\\textbackslash{}";
3215 case '°': case '±': case '²': case '³':
3216 case '×': case '÷': case '¹': case 'ª':
3217 case 'º': case '¬': case 'µ':
3218 if (current_view->buffer()->params.inputenc == "latin1") {
3219 os << "\\ensuremath{"
3228 case '|': case '<': case '>':
3229 // In T1 encoding, these characters exist
3230 if (lyxrc.fontenc == "T1") {
3232 //... but we should avoid ligatures
3233 if ((c == '>' || c == '<')
3235 && GetChar(i + 1) == c){
3236 os << "\\textcompwordmark{}";
3241 // Typewriter font also has them
3242 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3246 // Otherwise, we use what LaTeX
3250 os << "\\textless{}";
3254 os << "\\textgreater{}";
3258 os << "\\textbar{}";
3264 case '-': // "--" in Typewriter mode -> "-{}-"
3266 && GetChar(i + 1) == '-'
3267 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3276 os << "\\char`\\\"{}";
3281 if (current_view->buffer()->params.inputenc == "default") {
3290 case '%': case '#': case '{':
3297 os << "\\textasciitilde{}";
3302 os << "\\textasciicircum{}";
3306 case '*': case '[': case ']':
3307 // avoid being mistaken for optional arguments
3308 os << '{' << c << '}';
3313 // Blanks are printed before font switching.
3314 // Sure? I am not! (try nice-latex)
3315 // I am sure it's correct. LyX might be smarter
3316 // in the future, but for now, nothing wrong is
3321 /* idea for labels --- begin*/
3325 && font.family() != LyXFont::TYPEWRITER_FAMILY
3326 && GetChar(i + 1) == 'y'
3327 && GetChar(i + 2) == 'X') {
3335 && font.family() != LyXFont::TYPEWRITER_FAMILY
3336 && GetChar(i + 1) == 'e'
3337 && GetChar(i + 2) == 'X') {
3342 // Check for "LaTeX2e"
3345 && font.family() != LyXFont::TYPEWRITER_FAMILY
3346 && GetChar(i + 1) == 'a'
3347 && GetChar(i + 2) == 'T'
3348 && GetChar(i + 3) == 'e'
3349 && GetChar(i + 4) == 'X'
3350 && GetChar(i + 5) == '2'
3351 && GetChar(i + 6) == 'e') {
3356 // Check for "LaTeX"
3359 && font.family() != LyXFont::TYPEWRITER_FAMILY
3360 && GetChar(i + 1) == 'a'
3361 && GetChar(i + 2) == 'T'
3362 && GetChar(i + 3) == 'e'
3363 && GetChar(i + 4) == 'X') {
3367 /* idea for labels --- end*/
3368 } else if (c != '\0') {
3379 bool LyXParagraph::RoffContTableRows(ostream & os,
3380 LyXParagraph::size_type i,
3386 LyXFont font1(LyXFont::ALL_INHERIT);
3391 string fname2 = TmpFileName(string(), "RAT2");
3393 int cell = table->CellHasContRow(actcell);
3396 // first find the right position
3398 for (; i < size() && actcell < cell; ++i) {
3400 if (c == LyXParagraph::META_NEWLINE)
3405 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3408 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3410 font2 = GetFontSettings(i);
3411 if (font1.latex() != font2.latex()) {
3412 if (font2.latex() != LyXFont::OFF)
3417 case LyXParagraph::META_INSET:
3418 if ((inset = GetInset(i))) {
3420 stringstream ss(ios::in | ios::out);
3447 case LyXParagraph::META_NEWLINE:
3449 case LyXParagraph::META_HFILL:
3458 lyxerr.debug() << "RoffAsciiTable: "
3459 "NULL char in structure."
3464 cell = table->CellHasContRow(actcell);
3471 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3473 TexRow & foot_texrow,
3476 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3477 LyXParagraph * par = this;
3480 (par->depth == depth) &&
3481 (par->footnoteflag == footnoteflag)) {
3483 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3484 if (textclasslist.Style(current_view->buffer()->params.textclass,
3485 par->layout).isEnvironment()
3486 || par->pextra_type != PEXTRA_NONE) {
3487 par = par->TeXEnvironment(os, texrow,
3491 par = par->TeXOnePar(os, texrow, false,
3496 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3502 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3504 TexRow & foot_texrow,
3507 bool eindent_open = false;
3508 bool foot_this_level = false;
3509 // flags when footnotetext should be appended to file.
3510 static bool minipage_open = false;
3511 static int minipage_open_depth = 0;
3512 char par_sep = current_view->buffer()->params.paragraph_separation;
3514 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3516 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3518 LyXLayout const & style =
3519 textclasslist.Style(current_view->buffer()->params.textclass,
3522 if (pextra_type == PEXTRA_INDENT) {
3523 if (!pextra_width.empty()) {
3524 os << "\\begin{LyXParagraphIndent}{"
3525 << pextra_width << "}\n";
3527 //float ib = atof(pextra_widthp.c_str())/100;
3528 // string can't handle floats at present (971109)
3529 // so I'll do a conversion by hand knowing that
3530 // the limits are 0.0 to 1.0. ARRae.
3531 os << "\\begin{LyXParagraphIndent}{";
3532 switch (pextra_widthp.length()) {
3544 os << "\\columnwidth}\n";
3547 eindent_open = true;
3549 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3550 if (pextra_hfill && Previous() &&
3551 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3552 os << "\\hfill{}\n";
3555 if (par_sep == BufferParams::PARSEP_INDENT) {
3556 os << "{\\setlength\\parindent{0pt}\n";
3559 os << "\\begin{minipage}";
3560 switch(pextra_alignment) {
3561 case MINIPAGE_ALIGN_TOP:
3564 case MINIPAGE_ALIGN_MIDDLE:
3567 case MINIPAGE_ALIGN_BOTTOM:
3571 if (!pextra_width.empty()) {
3572 os << '{' << pextra_width << "}\n";
3574 //float ib = atof(par->pextra_width.c_str())/100;
3575 // string can't handle floats at present
3576 // so I'll do a conversion by hand knowing that
3577 // the limits are 0.0 to 1.0. ARRae.
3579 switch (pextra_widthp.length()) {
3591 os << "\\columnwidth}\n";
3594 if (par_sep == BufferParams::PARSEP_INDENT) {
3595 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3598 minipage_open = true;
3599 minipage_open_depth = depth;
3602 #ifdef WITH_WARNINGS
3603 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3604 //I disabled it because it breaks when lists span on several
3607 if (style.isEnvironment()){
3608 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3609 #ifdef FANCY_FOOTNOTE_CODE
3610 if (foot_count < 0) {
3611 // flag that footnote[mark][text] should be
3612 // used for any footnotes from now on
3614 foot_this_level = true;
3617 os << "\\begin{" << style.latexname() << "}{"
3618 << labelwidthstring << "}\n";
3619 } else if (style.labeltype == LABEL_BIBLIO) {
3621 os << "\\begin{" << style.latexname() << "}{"
3622 << bibitemWidthest(current_view->painter())
3624 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3625 #ifdef FANCY_FOOTNOTE_CODE
3626 if (foot_count < 0) {
3627 // flag that footnote[mark][text] should be
3628 // used for any footnotes from now on
3630 foot_this_level = true;
3633 os << "\\begin{" << style.latexname() << '}'
3634 << style.latexparam() << '\n';
3636 os << "\\begin{" << style.latexname() << '}'
3637 << style.latexparam() << '\n';
3640 LyXParagraph * par = this;
3642 par = par->TeXOnePar(os, texrow, false,
3643 foot, foot_texrow, foot_count);
3645 if (minipage_open && par && !style.isEnvironment() &&
3646 (par->pextra_type == PEXTRA_MINIPAGE) &&
3647 par->pextra_start_minipage) {
3648 os << "\\end{minipage}\n";
3650 if (par_sep == BufferParams::PARSEP_INDENT) {
3654 minipage_open = false;
3656 if (par && par->depth > depth) {
3657 if (textclasslist.Style(current_view->buffer()->params.textclass,
3658 par->layout).isParagraph()
3661 // How to handle this? (Lgb)
3662 //&& !suffixIs(os, "\n\n")
3664 // There should be at least one '\n' already
3665 // but we need there to be two for Standard
3666 // paragraphs that are depth-increment'ed to be
3667 // output correctly. However, tables can
3668 // also be paragraphs so don't adjust them.
3671 // Will it ever harm to have one '\n' too
3672 // many? i.e. that we sometimes will have
3673 // three in a row. (Lgb)
3677 par = par->TeXDeeper(os, texrow,
3678 foot, foot_texrow, foot_count);
3680 if (par && par->layout == layout && par->depth == depth &&
3681 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3682 if (par->pextra_hfill && par->Previous() &&
3683 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3684 os << "\\hfill{}\n";
3687 if (par_sep == BufferParams::PARSEP_INDENT) {
3688 os << "{\\setlength\\parindent{0pt}\n";
3691 os << "\\begin{minipage}";
3692 switch(par->pextra_alignment) {
3693 case MINIPAGE_ALIGN_TOP:
3696 case MINIPAGE_ALIGN_MIDDLE:
3699 case MINIPAGE_ALIGN_BOTTOM:
3703 if (!par->pextra_width.empty()) {
3704 os << '{' << par->pextra_width << "}\n";
3706 //float ib = atof(par->pextra_widthp.c_str())/100;
3707 // string can't handle floats at present
3708 // so I'll do a conversion by hand knowing that
3709 // the limits are 0.0 to 1.0. ARRae.
3711 switch (par->pextra_widthp.length()) {
3716 os << "0." << par->pextra_widthp;
3719 os << "0.0" << par->pextra_widthp;
3721 os << "\\columnwidth}\n";
3724 if (par_sep == BufferParams::PARSEP_INDENT) {
3725 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3728 minipage_open = true;
3729 minipage_open_depth = par->depth;
3732 && par->layout == layout
3733 && par->depth == depth
3734 && par->pextra_type == pextra_type
3735 && par->footnoteflag == footnoteflag);
3737 if (style.isEnvironment()) {
3738 os << "\\end{" << style.latexname() << '}';
3739 // maybe this should go after the minipage closes?
3740 if (foot_this_level) {
3741 if (foot_count >= 1) {
3742 if (foot_count > 1) {
3743 os << "\\addtocounter{footnote}{-"
3748 texrow += foot_texrow;
3750 foot_texrow.reset();
3755 if (minipage_open && (minipage_open_depth == depth) &&
3756 (!par || par->pextra_start_minipage ||
3757 par->pextra_type != PEXTRA_MINIPAGE)) {
3758 os << "\\end{minipage}\n";
3760 if (par_sep == BufferParams::PARSEP_INDENT) {
3764 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3765 os << "\\medskip\n\n";
3769 minipage_open = false;
3772 os << "\\end{LyXParagraphIndent}\n";
3775 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3776 && par->pextra_hfill)) {
3780 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3781 return par; // ale970302
3785 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3786 ostream & foot, TexRow & foot_texrow,
3790 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3791 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3792 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3793 "No footnote!" << endl;
3795 LyXParagraph * par = this;
3796 LyXLayout const & style =
3797 textclasslist.Style(current_view->buffer()->params.textclass,
3798 previous->GetLayout());
3800 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3801 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3802 "Float other than footnote in command"
3803 " with moving argument is illegal" << endl;
3806 if (footnotekind != LyXParagraph::FOOTNOTE
3807 && footnotekind != LyXParagraph::MARGIN
3810 // How to solve this?
3811 //&& !suffixIs(file, '\n')
3813 // we need to ensure that real floats like tables and figures
3814 // have their \begin{} on a new line otherwise we can get
3815 // incorrect results when using the endfloat.sty package
3816 // especially if two floats follow one another. ARRae 981022
3817 // NOTE: if the file is length 0 it must have just been
3818 // written out so we assume it ended with a '\n'
3820 // As far as I can see there is never any harm in writing
3821 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3826 bool moving_arg = false;
3827 bool need_closing = false;
3828 bool is_rtl = isRightToLeftPar();
3830 if (is_rtl != parent_is_rtl) {
3835 need_closing = true;
3838 BufferParams * params = ¤t_view->buffer()->params;
3839 bool footer_in_body = true;
3840 switch (footnotekind) {
3841 case LyXParagraph::FOOTNOTE:
3842 if (style.intitle) {
3843 os << "\\thanks{\n";
3844 footer_in_body = false;
3847 if (foot_count == -1) {
3848 // we're at depth 0 so we can use:
3849 os << "\\footnote{%\n";
3850 footer_in_body = false;
3852 os << "\\footnotemark{}%\n";
3854 // we only need this when there are
3855 // multiple footnotes
3856 os << "\\stepcounter{footnote}";
3858 os << "\\footnotetext{%\n";
3859 foot_texrow.start(this, 0);
3860 foot_texrow.newline();
3865 case LyXParagraph::MARGIN:
3866 os << "\\marginpar{\n";
3868 case LyXParagraph::FIG:
3869 if (pextra_type == PEXTRA_FLOATFLT
3870 && (!pextra_width.empty()
3871 || !pextra_widthp.empty())) {
3872 if (!pextra_width.empty())
3873 os << "\\begin{floatingfigure}{"
3874 << pextra_width << "}\n";
3876 os << "\\begin{floatingfigure}{"
3877 << atoi(pextra_widthp.c_str())/100.0
3878 << "\\textwidth}\n";
3880 os << "\\begin{figure}";
3881 if (!params->float_placement.empty()) {
3882 os << '[' << params->float_placement << "]\n";
3888 case LyXParagraph::TAB:
3889 os << "\\begin{table}";
3890 if (!params->float_placement.empty()) {
3891 os << '[' << params->float_placement << "]\n";
3896 case LyXParagraph::WIDE_FIG:
3897 os << "\\begin{figure*}";
3898 if (!params->float_placement.empty()) {
3899 os << '[' << params->float_placement << "]\n";
3904 case LyXParagraph::WIDE_TAB:
3905 os << "\\begin{table*}";
3906 if (!params->float_placement.empty()) {
3907 os << '[' << params->float_placement << "]\n";
3912 case LyXParagraph::ALGORITHM:
3913 os << "\\begin{algorithm}\n";
3918 if (footnotekind != LyXParagraph::FOOTNOTE
3919 || !footer_in_body) {
3920 // Process text for all floats except footnotes in body
3922 LyXLayout const & style =
3924 .Style(current_view->buffer()->params
3928 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3930 if (style.isEnvironment()
3931 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3932 // Allows the use of minipages within float
3933 // environments. Shouldn't be circular because
3934 // we don't support footnotes inside
3935 // floats (yet). ARRae
3936 par = par->TeXEnvironment(os, texrow,
3940 par = par->TeXOnePar(os, texrow, moving_arg,
3945 if (par && !par->IsDummy() && par->depth > depth) {
3946 par = par->TeXDeeper(os, texrow,
3950 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3952 // process footnotes > depth 0 or in environments separately
3953 // NOTE: Currently don't support footnotes within footnotes
3954 // even though that is possible using the \footnotemark
3956 std::ostringstream dummy;
3960 TexRow dummy_texrow;
3961 int dummy_count = 0;
3963 LyXLayout const & style =
3965 .Style(current_view->buffer()->params
3969 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3971 if (style.isEnvironment()
3972 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3973 // Allows the use of minipages within float
3974 // environments. Shouldn't be circular because
3975 // we don't support footnotes inside
3976 // floats (yet). ARRae
3977 par = par->TeXEnvironment(foot, foot_texrow,
3978 dummy, dummy_texrow,
3981 par = par->TeXOnePar(foot, foot_texrow,
3983 dummy, dummy_texrow,
3987 if (par && !par->IsDummy() && par->depth > depth) {
3988 par = par->TeXDeeper(foot, foot_texrow,
3989 dummy, dummy_texrow,
3993 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3995 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3996 "Footnote in a Footnote -- not supported"
3999 #ifndef HAVE_OSTREAM
4000 delete [] dummy.str();
4004 switch (footnotekind) {
4005 case LyXParagraph::FOOTNOTE:
4006 if (footer_in_body) {
4007 // This helps tell which of the multiple
4008 // footnotetexts an error was in.
4010 foot_texrow.newline();
4015 case LyXParagraph::MARGIN:
4018 case LyXParagraph::FIG:
4019 if (pextra_type == PEXTRA_FLOATFLT
4020 && (!pextra_width.empty()
4021 || !pextra_widthp.empty()))
4022 os << "\\end{floatingfigure}";
4024 os << "\\end{figure}";
4026 case LyXParagraph::TAB:
4027 os << "\\end{table}";
4029 case LyXParagraph::WIDE_FIG:
4030 os << "\\end{figure*}";
4032 case LyXParagraph::WIDE_TAB:
4033 os << "\\end{table*}";
4035 case LyXParagraph::ALGORITHM:
4036 os << "\\end{algorithm}";
4043 if (footnotekind != LyXParagraph::FOOTNOTE
4044 && footnotekind != LyXParagraph::MARGIN) {
4045 // we need to ensure that real floats like tables and figures
4046 // have their \end{} on a line of their own otherwise we can
4047 // get incorrect results when using the endfloat.sty package.
4052 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4057 bool LyXParagraph::IsDummy() const
4059 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4060 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4064 void LyXParagraph::SetPExtraType(int type, char const * width,
4065 char const * widthp)
4068 pextra_width = width;
4069 pextra_widthp = widthp;
4071 if (textclasslist.Style(current_view->buffer()->params.textclass,
4072 layout).isEnvironment()) {
4077 while (par && (par->layout == layout)
4078 && (par->depth == depth)) {
4080 par = par->Previous();
4082 par = par->FirstPhysicalPar();
4083 while (par && par->depth > depth) {
4084 par = par->Previous();
4086 par = par->FirstPhysicalPar();
4090 while (par && (par->layout == layout)
4091 && (par->depth == depth)) {
4092 par->pextra_type = type;
4093 par->pextra_width = width;
4094 par->pextra_widthp = widthp;
4095 par = par->NextAfterFootnote();
4096 if (par && (par->depth > depth))
4097 par->SetPExtraType(type, width, widthp);
4098 while (par && ((par->depth > depth) || par->IsDummy()))
4099 par = par->NextAfterFootnote();
4105 void LyXParagraph::UnsetPExtraType()
4107 if (pextra_type == PEXTRA_NONE)
4110 pextra_type = PEXTRA_NONE;
4111 pextra_width.erase();
4112 pextra_widthp.erase();
4114 if (textclasslist.Style(current_view->buffer()->params.textclass,
4115 layout).isEnvironment()) {
4120 while (par && (par->layout == layout)
4121 && (par->depth == depth)) {
4123 par = par->Previous();
4125 par = par->FirstPhysicalPar();
4126 while (par && par->depth > depth) {
4127 par = par->Previous();
4129 par = par->FirstPhysicalPar();
4133 while (par && (par->layout == layout)
4134 && (par->depth == depth)) {
4135 par->pextra_type = PEXTRA_NONE;
4136 par->pextra_width.erase();
4137 par->pextra_widthp.erase();
4138 par = par->NextAfterFootnote();
4139 if (par && (par->depth > depth))
4140 par->UnsetPExtraType();
4141 while (par && ((par->depth > depth) || par->IsDummy()))
4142 par = par->NextAfterFootnote();
4148 bool LyXParagraph::IsHfill(size_type pos) const
4150 return IsHfillChar(GetChar(pos));
4154 bool LyXParagraph::IsInset(size_type pos) const
4156 return IsInsetChar(GetChar(pos));
4160 bool LyXParagraph::IsFloat(size_type pos) const
4162 return IsFloatChar(GetChar(pos));
4166 bool LyXParagraph::IsNewline(size_type pos) const
4168 return pos >= 0 && IsNewlineChar(GetChar(pos));
4172 bool LyXParagraph::IsSeparator(size_type pos) const
4174 return IsSeparatorChar(GetChar(pos));
4178 bool LyXParagraph::IsLineSeparator(size_type pos) const
4180 return IsLineSeparatorChar(GetChar(pos));
4184 bool LyXParagraph::IsKomma(size_type pos) const
4186 return IsKommaChar(GetChar(pos));
4190 /// Used by the spellchecker
4191 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4193 unsigned char c = GetChar(pos);
4194 if (IsLetterChar(c))
4196 // '\0' is not a letter, allthough every string contains "" (below)
4199 // We want to pass the ' and escape chars to ispell
4200 string extra = lyxrc.isp_esc_chars + '\'';
4204 return contains(extra, ch);
4208 bool LyXParagraph::IsWord(size_type pos ) const
4210 return IsWordChar(GetChar(pos)) ;
4214 Language const * LyXParagraph::getParLanguage() const
4218 return FirstPhysicalPar()->GetFirstFontSettings()
4221 for (size_type pos = 0; pos < size(); ++pos)
4223 return GetFontSettings(pos).language();
4224 return GetFirstFontSettings().language();
4227 return previous->getParLanguage();
4229 return current_view->buffer()->params.language_info;
4233 bool LyXParagraph::isRightToLeftPar() const
4235 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4239 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4241 for(size_type i = 0; i < size(); ++i) {
4242 LyXFont font = GetFontSettings(i);
4243 if (font.language() == from) {
4244 font.setLanguage(to);
4251 bool LyXParagraph::isMultiLingual()
4253 Language const * doc_language =
4254 current_view->buffer()->params.language_info;
4255 for(size_type i = 0; i < size(); ++i) {
4256 LyXFont font = GetFontSettings(i);
4257 if (font.language() != doc_language)
4264 // Convert the paragraph to a string.
4265 // Used for building the table of contents
4266 string LyXParagraph::String(bool label)
4269 if (label && !IsDummy())
4270 s += labelstring + ' ';
4271 string::size_type len = s.size();
4273 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4274 unsigned char c = GetChar(i);
4277 else if (c == META_INSET &&
4278 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4280 std::ostringstream ost;
4281 GetInset(i)->Ascii(ost);
4284 GetInset(i)->Ascii(ost);
4287 s += subst(ost.str(),'\n',' ');
4291 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4292 s += NextAfterFootnote()->String(false);
4295 if (isRightToLeftPar())
4296 reverse(s.begin() + len,s.end());
4302 string LyXParagraph::String(LyXParagraph::size_type beg,
4303 LyXParagraph::size_type end)
4307 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4308 unsigned char c = GetChar(i);
4311 else if (c == META_INSET) {
4313 std::ostringstream ost;
4314 GetInset(i)->Ascii(ost);
4317 GetInset(i)->Ascii(ost);
4320 s += subst(ost.str(),'\n',' ');
4324 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4325 s += NextAfterFootnote()->String(false);
4328 if (isRightToLeftPar())
4329 reverse(s.begin(), s.end());