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"
42 int tex_code_break_column = 72; // needs non-zero initialization. set later.
43 // this is a bad idea, but how can LyXParagraph find its buffer to get
44 // parameters? (JMarc)
45 extern BufferView * current_view;
49 extern string bibitemWidthest(Painter &);
51 // this is a minibuffer
52 static char minibuffer_char;
53 static LyXFont minibuffer_font;
54 static Inset * minibuffer_inset;
57 // Initialization of the counter for the paragraph id's,
58 // declared in lyxparagraph.h
59 unsigned int LyXParagraph::paragraph_id = 0;
62 LyXParagraph::LyXParagraph()
64 text.reserve(500); // is this number too big?
66 for (int i = 0; i < 10; ++i) setCounter(i , 0);
72 footnoteflag = LyXParagraph::NO_FOOTNOTE;
73 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
75 align = LYX_ALIGN_BLOCK;
77 /* table stuff -- begin*/
79 /* table stuff -- end*/
82 bibkey = 0; // ale970302
87 // This konstruktor inserts the new paragraph in a list.
88 LyXParagraph::LyXParagraph(LyXParagraph * par)
91 par->text.resize(par->text.size());
93 for (int i = 0; i < 10; ++i) setCounter(i, 0);
97 // double linked list begin
100 next->previous = this;
102 previous->next = this;
104 footnoteflag = LyXParagraph::NO_FOOTNOTE;
105 footnotekind = LyXParagraph::FOOTNOTE;
107 /* table stuff -- begin*/
109 /* table stuff -- end*/
111 id_ = paragraph_id++;
113 bibkey = 0; // ale970302
119 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
120 char footflag, char dth) const
122 LyXFont font1, font2;
127 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
129 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
131 // The beginning or the end of a footnote environment?
132 if (footflag != footnoteflag) {
133 footflag = footnoteflag;
135 os << "\n\\begin_float "
136 << string_footnotekinds[footnotekind]
139 os << "\n\\end_float ";
143 // The beginning or end of a deeper (i.e. nested) area?
146 while (depth > dth) {
147 os << "\n\\begin_deeper ";
151 while (depth < dth) {
152 os << "\n\\end_deeper ";
158 // First write the layout
160 << textclasslist.NameOfLayout(params.textclass, layout)
163 // Maybe some vertical spaces.
164 if (added_space_top.kind() != VSpace::NONE)
165 os << "\\added_space_top "
166 << added_space_top.asLyXCommand() << " ";
167 if (added_space_bottom.kind() != VSpace::NONE)
168 os << "\\added_space_bottom "
169 << added_space_bottom.asLyXCommand() << " ";
171 // Maybe the paragraph has special spacing
172 spacing.writeFile(os, true);
174 // The labelwidth string used in lists.
175 if (!labelwidthstring.empty())
176 os << "\\labelwidthstring "
177 << labelwidthstring << '\n';
179 // Lines above or below?
183 os << "\\line_bottom ";
185 // Pagebreaks above or below?
187 os << "\\pagebreak_top ";
188 if (pagebreak_bottom)
189 os << "\\pagebreak_bottom ";
191 // Start of appendix?
192 if (start_of_appendix)
193 os << "\\start_of_appendix ";
200 if (align != LYX_ALIGN_LAYOUT) {
202 case LYX_ALIGN_LEFT: h = 1; break;
203 case LYX_ALIGN_RIGHT: h = 2; break;
204 case LYX_ALIGN_CENTER: h = 3; break;
205 default: h = 0; break;
207 os << "\\align " << string_align[h] << " ";
209 if (pextra_type != PEXTRA_NONE) {
210 os << "\\pextra_type " << pextra_type;
211 if (pextra_type == PEXTRA_MINIPAGE) {
212 os << " \\pextra_alignment "
215 os << " \\pextra_hfill "
217 if (pextra_start_minipage)
218 os << " \\pextra_start_minipage "
219 << pextra_start_minipage;
221 if (!pextra_width.empty()) {
222 os << " \\pextra_width "
223 << VSpace(pextra_width).asLyXCommand();
224 } else if (!pextra_widthp.empty()) {
225 os << " \\pextra_widthp "
231 // Dummy layout. This means that a footnote ended.
232 os << "\n\\end_float ";
233 footflag = LyXParagraph::NO_FOOTNOTE;
236 // It might be a table.
238 os << "\\LyXTable\n";
246 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
249 for (size_type i = 0; i < size(); ++i) {
255 // Write font changes
256 font2 = GetFontSettings(i);
257 if (font2 != font1) {
258 font2.lyxWriteChanges(font1, os);
267 Inset const * inset = GetInset(i);
269 if (inset->DirectWrite()) {
270 // international char, let it write
271 // code directly so it's shorter in
275 os << "\n\\begin_inset ";
277 os << "\n\\end_inset \n\n";
283 os << "\n\\newline \n";
287 os << "\n\\hfill \n";
291 case META_PROTECTED_SEPARATOR:
292 os << "\n\\protected_separator \n";
297 os << "\n\\backslash \n";
301 if (i + 1 < size() && GetChar(i + 1) == ' ') {
308 if ((column > 70 && c == ' ')
313 // this check is to amend a bug. LyX sometimes
314 // inserts '\0' this could cause problems.
318 lyxerr << "ERROR (LyXParagraph::writeFile):"
319 " NULL char in structure." << endl;
325 // now write the next paragraph
327 next->writeFile(os, params, footflag, dth);
331 void LyXParagraph::validate(LaTeXFeatures & features) const
333 BufferParams const & params = features.bufferParams();
335 // this will be useful later
336 LyXLayout const & layout =
337 textclasslist.Style(params.textclass,
341 if (line_top || line_bottom)
342 features.lyxline = true;
343 if (!spacing.isDefault())
344 features.setspace = true;
347 features.layout[GetLayout()] = true;
350 Language const * doc_language = params.language_info;
352 for (FontList::const_iterator cit = fontlist.begin();
353 cit != fontlist.end(); ++cit) {
354 if ((*cit).font.noun() == LyXFont::ON) {
355 lyxerr[Debug::LATEX] << "font.noun: "
356 << (*cit).font.noun()
358 features.noun = true;
359 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
360 << (*cit).font.stateText()
363 switch ((*cit).font.color()) {
365 case LColor::inherit:
369 features.color = true;
370 lyxerr[Debug::LATEX] << "Color enabled. Font: "
371 << (*cit).font.stateText()
374 Language const * language = (*cit).font.language();
375 if (language != doc_language && language != default_language) {
376 features.UsedLanguages.insert(language);
377 lyxerr[Debug::LATEX] << "Found language "
378 << language->lang << endl;
383 for (InsetList::const_iterator cit = insetlist.begin();
384 cit != insetlist.end(); ++cit) {
386 (*cit).inset->Validate(features);
389 if (table && table->IsLongTable())
390 features.longtable = true;
391 if (pextra_type == PEXTRA_INDENT)
392 features.LyXParagraphIndent = true;
393 if (pextra_type == PEXTRA_FLOATFLT)
394 features.floatflt = true;
395 if (layout.needprotect
396 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
397 features.NeedLyXFootnoteCode = true;
398 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
399 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
400 features.NeedLyXMinipageIndent = true;
401 if (table && table->NeedRotating())
402 features.rotating = true;
403 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
404 features.algorithm = true;
408 // First few functions needed for cut and paste and paragraph breaking.
409 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
411 minibuffer_char = GetChar(pos);
412 minibuffer_font = GetFontSettings(pos);
413 minibuffer_inset = 0;
414 if (minibuffer_char == LyXParagraph::META_INSET) {
416 minibuffer_inset = GetInset(pos)->Clone();
418 minibuffer_inset = 0;
419 minibuffer_char = ' ';
420 // This reflects what GetInset() does (ARRae)
426 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
428 minibuffer_char = GetChar(pos);
429 minibuffer_font = GetFontSettings(pos);
430 minibuffer_inset = 0;
431 if (minibuffer_char == LyXParagraph::META_INSET) {
433 minibuffer_inset = GetInset(pos);
434 // This is a little hack since I want exactly
435 // the inset, not just a clone. Otherwise
436 // the inset would be deleted when calling Erase(pos)
438 InsetList::iterator it = lower_bound(insetlist.begin(),
441 if (it != insetlist.end() && (*it).pos == pos)
444 minibuffer_inset = 0;
445 minibuffer_char = ' ';
446 // This reflects what GetInset() does (ARRae)
451 // Erase(pos); now the caller is responsible for that.
455 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
457 if ((minibuffer_char == LyXParagraph::META_INSET) &&
458 !InsertInsetAllowed(minibuffer_inset))
460 InsertChar(pos, minibuffer_char);
461 SetFont(pos, minibuffer_font);
462 if (minibuffer_char == LyXParagraph::META_INSET)
463 InsertInset(pos, minibuffer_inset);
471 void LyXParagraph::Clear()
476 pagebreak_top = false;
477 pagebreak_bottom = false;
479 added_space_top = VSpace(VSpace::NONE);
480 added_space_bottom = VSpace(VSpace::NONE);
481 spacing.set(Spacing::Default);
483 align = LYX_ALIGN_LAYOUT;
487 pextra_type = PEXTRA_NONE;
488 pextra_width.clear();
489 pextra_widthp.clear();
490 pextra_alignment = MINIPAGE_ALIGN_TOP;
491 pextra_hfill = false;
492 pextra_start_minipage = false;
495 labelwidthstring.clear();
499 start_of_appendix = false;
503 // the destructor removes the new paragraph from the list
504 LyXParagraph::~LyXParagraph()
507 previous->next = next;
509 next->previous = previous;
511 for (InsetList::iterator it = insetlist.begin();
512 it != insetlist.end(); ++it) {
516 /* table stuff -- begin*/
518 /* table stuff -- end*/
523 //lyxerr << "LyXParagraph::paragraph_id = "
524 // << LyXParagraph::paragraph_id << endl;
528 void LyXParagraph::Erase(LyXParagraph::size_type pos)
530 // > because last is the next unused position, and you can
531 // use it if you want
533 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
534 NextAfterFootnote()->Erase(pos - text.size() - 1);
536 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
537 "position does not exist." << endl;
540 if (pos < size()) { // last is free for insertation, but should be empty
541 // if it is an inset, delete the inset entry
542 if (text[pos] == LyXParagraph::META_INSET) {
544 InsetList::iterator it = lower_bound(insetlist.begin(),
547 if (it != insetlist.end() && (*it).pos == pos) {
552 text.erase(text.begin() + pos);
553 // Erase entries in the tables.
554 for (FontList::iterator it = fontlist.begin();
555 it != fontlist.end(); ++it) {
556 if (pos >= (*it).pos && pos <= (*it).pos_end) {
557 if ((*it).pos == (*it).pos_end) {
558 // If it is a multi-character font
559 // entry, we just make it smaller
560 // (see update below), otherwise we
567 // Update all other entries.
568 for (FontList::iterator it = fontlist.begin();
569 it != fontlist.end(); ++it) {
572 if ((*it).pos_end >= pos)
576 // Update the inset table.
577 for (InsetList::iterator it = upper_bound(insetlist.begin(),
580 it != insetlist.end(); ++it)
583 lyxerr << "ERROR (LyXParagraph::Erase): "
584 "can't erase non-existant char." << endl;
589 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
591 // > because last is the next unused position, and you can
592 // use it if you want
595 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
596 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
599 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
600 "position does not exist." << endl;
603 text.insert(text.begin() + pos, c);
604 // Update the font table.
605 for (FontList::iterator it = fontlist.begin();
606 it != fontlist.end(); ++it) {
607 if ((*it).pos >= pos)
609 if ((*it).pos_end >= pos)
613 // Update the inset table.
614 for (InsetList::iterator it = lower_bound(insetlist.begin(),
617 it != insetlist.end(); ++it)
622 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
625 // > because last is the next unused position, and you can
626 // use it if you want
629 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
631 ->InsertInset(pos - text.size() - 1, inset);
633 lyxerr << "ERROR (LyXParagraph::InsertInset): "
634 "position does not exist: " << pos << endl;
637 if (text[pos] != LyXParagraph::META_INSET) {
638 lyxerr << "ERROR (LyXParagraph::InsertInset): "
639 "there is no LyXParagraph::META_INSET" << endl;
644 // Add a new entry in the inset table.
645 InsetList::iterator it = lower_bound(insetlist.begin(),
648 if (it != insetlist.end() && (*it).pos == pos)
649 lyxerr << "ERROR (LyXParagraph::InsertInset): "
650 "there is an inset in position: " << pos << endl;
652 insetlist.insert(it, InsetTable(pos,inset));
657 bool LyXParagraph::InsertInsetAllowed(Inset *inset)
660 printf("CODE:%d\n",inset->LyxCode());
661 return inset_owner->InsertInsetAllowed(inset);
666 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
670 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
671 return NextAfterFootnote()
672 ->GetInset(pos - text.size() - 1);
674 lyxerr << "ERROR (LyXParagraph::GetInset): "
675 "position does not exist: "
681 InsetList::iterator it = lower_bound(insetlist.begin(),
684 if (it != insetlist.end() && (*it).pos == pos)
687 lyxerr << "ERROR (LyXParagraph::GetInset): "
688 "Inset does not exist: " << pos << endl;
689 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
690 // Did this commenting out introduce a bug? So far I have not
691 // see any, please enlighten me. (Lgb)
692 // My guess is that since the inset does not exist, we might
693 // as well replace it with a space to prevent craches. (Asger)
698 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
702 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
703 return NextAfterFootnote()
704 ->GetInset(pos - text.size() - 1);
706 lyxerr << "ERROR (LyXParagraph::GetInset): "
707 "position does not exist: "
713 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
716 if (cit != insetlist.end() && (*cit).pos == pos)
719 lyxerr << "ERROR (LyXParagraph::GetInset): "
720 "Inset does not exist: " << pos << endl;
721 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
722 // Did this commenting out introduce a bug? So far I have not
723 // see any, please enlighten me. (Lgb)
724 // My guess is that since the inset does not exist, we might
725 // as well replace it with a space to prevent craches. (Asger)
730 // Gets uninstantiated font setting at position.
731 // Optimized after profiling. (Asger)
732 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
735 #ifdef SORTED_FONT_LIST
736 for (FontList::const_iterator cit = fontlist.begin();
737 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
738 if (pos >= (*cit).pos)
741 for (FontList::const_iterator cit = fontlist.begin();
742 cit != fontlist.end(); ++cit)
743 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
747 // > because last is the next unused position, and you can
748 // use it if you want
749 else if (pos > size()) {
751 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
752 return NextAfterFootnote()
753 ->GetFontSettings(pos - text.size() - 1);
755 // Why is it an error to ask for the font of a
756 // position that does not exist? Would it be
757 // enough for this to be enabled on debug?
758 // We want strict error checking, but it's ok to only
759 // have it when debugging. (Asger)
760 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
761 "position does not exist. "
762 << pos << " (" << static_cast<int>(pos)
765 } else if (pos > 0) {
766 return GetFontSettings(pos - 1);
767 } else // pos = size() = 0
768 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
770 return LyXFont(LyXFont::ALL_INHERIT);
773 // Gets uninstantiated font setting at position 0
774 LyXFont LyXParagraph::GetFirstFontSettings() const
777 #ifdef SORTED_FONT_LIST
778 if (!fontlist.empty() && fontlist.front().pos == 0)
779 return fontlist.front().font;
781 for (FontList::const_iterator cit = fontlist.begin();
782 cit != fontlist.end(); ++cit)
783 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
786 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
787 return NextAfterFootnote()->GetFirstFontSettings();
788 return LyXFont(LyXFont::ALL_INHERIT);
791 // Gets the fully instantiated font at a given position in a paragraph
792 // This is basically the same function as LyXText::GetFont() in text2.C.
793 // The difference is that this one is used for generating the LaTeX file,
794 // and thus cosmetic "improvements" are disallowed: This has to deliver
795 // the true picture of the buffer. (Asger)
796 // If position is -1, we get the layout font of the paragraph.
797 // If position is -2, we get the font of the manual label of the paragraph.
798 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
801 LyXLayout const & layout =
802 textclasslist.Style(current_view->buffer()->params.textclass,
804 LyXParagraph::size_type main_body = 0;
805 if (layout.labeltype == LABEL_MANUAL)
806 main_body = BeginningOfMainBody();
811 layoutfont = layout.labelfont;
813 layoutfont = layout.font;
814 tmpfont = GetFontSettings(pos);
815 tmpfont.realize(layoutfont);
817 // process layoutfont for pos == -1 and labelfont for pos < -1
819 tmpfont = layout.font;
821 tmpfont = layout.labelfont;
822 tmpfont.setLanguage(getParLanguage());
825 // check for environment font information
826 char par_depth = GetDepth();
827 LyXParagraph const * par = this;
828 while (par && par_depth && !tmpfont.resolved()) {
829 par = par->DepthHook(par_depth - 1);
831 tmpfont.realize(textclasslist.
832 Style(current_view->buffer()->params.textclass,
833 par->GetLayout()).font);
834 par_depth = par->GetDepth();
838 tmpfont.realize(textclasslist
839 .TextClass(current_view->buffer()->params.textclass)
845 /// Returns the height of the highest font in range
847 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
848 LyXParagraph::size_type endpos) const
850 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
851 for (FontList::const_iterator cit = fontlist.begin();
852 cit != fontlist.end(); ++cit) {
853 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
854 LyXFont::FONT_SIZE size = (*cit).font.size();
855 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
863 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
870 // > because last is the next unused position, and you can
871 // use it if you want
872 else if (pos > size()) {
873 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
874 return NextAfterFootnote()
875 ->GetChar(pos - text.size() - 1);
877 lyxerr << "ERROR (LyXParagraph::GetChar): "
878 "position does not exist."
879 << pos << " (" << static_cast<int>(pos)
881 // Assert(false); // This triggers sometimes...
886 // We should have a footnote environment.
887 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
888 // Notice that LyX does request the
889 // last char from time to time. (Asger)
890 //lyxerr << "ERROR (LyXParagraph::GetChar): "
891 // "expected footnote." << endl;
894 switch (next->footnotekind) {
895 case LyXParagraph::FOOTNOTE:
896 return LyXParagraph::META_FOOTNOTE;
897 case LyXParagraph::MARGIN:
898 return LyXParagraph::META_MARGIN;
899 case LyXParagraph::FIG:
900 case LyXParagraph::WIDE_FIG:
901 return LyXParagraph::META_FIG;
902 case LyXParagraph::TAB:
903 case LyXParagraph::WIDE_TAB:
904 return LyXParagraph::META_TAB;
905 case LyXParagraph::ALGORITHM:
906 return LyXParagraph::META_ALGORITHM;
908 return '\0'; // to shut up gcc
913 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
920 // > because last is the next unused position, and you can
921 // use it if you want
922 else if (pos > size()) {
923 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
924 return NextAfterFootnote()
925 ->GetChar(pos - text.size() - 1);
927 lyxerr << "ERROR (LyXParagraph::GetChar const): "
928 "position does not exist."
929 << pos << " (" << static_cast<int>(pos)
935 // We should have a footnote environment.
936 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
937 // Notice that LyX does request the
938 // last char from time to time. (Asger)
939 //lyxerr << "ERROR (LyXParagraph::GetChar): "
940 // "expected footnote." << endl;
943 switch (next->footnotekind) {
944 case LyXParagraph::FOOTNOTE:
945 return LyXParagraph::META_FOOTNOTE;
946 case LyXParagraph::MARGIN:
947 return LyXParagraph::META_MARGIN;
948 case LyXParagraph::FIG:
949 case LyXParagraph::WIDE_FIG:
950 return LyXParagraph::META_FIG;
951 case LyXParagraph::TAB:
952 case LyXParagraph::WIDE_TAB:
953 return LyXParagraph::META_TAB;
954 case LyXParagraph::ALGORITHM:
955 return LyXParagraph::META_ALGORITHM;
957 return '\0'; // to shut up gcc
962 // return an string of the current word, and the end of the word in lastpos.
963 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
967 // the current word is defined as starting at the first character
968 // from the immediate left of lastpospos which meets the definition
969 // of IsLetter(), continuing to the last character to the right
970 // of this meeting IsLetter.
976 // move back until we have a letter
978 //there's no real reason to have firstpos & lastpos as
979 //separate variables as this is written, but maybe someon
980 // will want to return firstpos in the future.
982 //since someone might have typed a punctuation first
983 int firstpos = lastpos;
985 while ((firstpos >= 0) && !IsLetter(firstpos))
988 // now find the beginning by looking for a nonletter
990 while ((firstpos>= 0) && IsLetter(firstpos))
993 // the above is now pointing to the preceeding non-letter
997 // so copy characters into theword until we get a nonletter
998 // note that this can easily exceed lastpos, wich means
999 // that if used in the middle of a word, the whole word
1002 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1009 LyXParagraph::size_type LyXParagraph::Last() const
1011 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1012 return text.size() + NextAfterFootnote()->Last() + 1;
1013 // the 1 is the symbol
1020 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1022 // > because last is the next unused position, and you can
1023 // use it if you want
1026 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1027 return NextAfterFootnote()
1028 ->ParFromPos(pos - text.size() - 1);
1030 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1031 "position does not exist." << endl;
1038 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1040 // > because last is the next unused position, and you can
1041 // use it if you want
1044 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1045 return NextAfterFootnote()
1046 ->PositionInParFromPos(pos - text.size() - 1);
1049 "ERROR (LyXParagraph::PositionInParFromPos): "
1050 "position does not exist." << endl;
1058 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1059 LyXFont const & font)
1061 // > because last is the next unused position, and you can
1062 // use it if you want
1065 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1066 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1069 lyxerr << "ERROR (LyXParagraph::SetFont): "
1070 "position does not exist." << endl;
1074 LyXFont patternfont(LyXFont::ALL_INHERIT);
1076 // First, reduce font against layout/label font
1077 // Update: The SetCharFont() routine in text2.C already
1078 // reduces font, so we don't need to do that here. (Asger)
1079 // No need to simplify this because it will disappear
1080 // in a new kernel. (Asger)
1081 // Next search font table
1082 FontList::iterator tmp = fontlist.begin();
1083 for (; tmp != fontlist.end(); ++tmp) {
1084 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1088 if (tmp == fontlist.end()) { // !found
1089 // if we did not find a font entry, but if the font at hand
1090 // is the same as default, we just forget it
1091 if (font == patternfont) return;
1093 // ok, we did not find a font entry. But maybe there is exactly
1094 // the needed font ientry one position left
1095 FontList::iterator tmp2 = fontlist.begin();
1096 for (; tmp2 != fontlist.end(); ++tmp2) {
1097 if (pos - 1 >= (*tmp2).pos
1098 && pos - 1 <= (*tmp2).pos_end)
1101 if (tmp2 != fontlist.end()) {
1102 // ok there is one, maybe it is exactly
1104 if ((*tmp2).font == font) {
1105 // put the position under the font
1110 // Add a new entry in the
1111 // fontlist for the position
1115 ft.font = font; // or patternfont
1116 // It seems that using font instead of patternfont here
1117 // fixes all the problems. This also surfaces a "bug" in
1119 fontlist.insert(fontlist.begin(), ft);
1120 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1122 // more than one character
1123 if (pos == (*tmp).pos) {
1124 // maybe we should enlarge the left fonttable
1125 FontList::iterator tmp2 = fontlist.begin();
1126 for (; tmp2 != fontlist.end(); ++tmp2) {
1127 if (pos - 1 >= (*tmp2).pos
1128 && pos - 1 <= (*tmp2).pos_end)
1131 // Is there is one, and is it exactly
1133 if (tmp2 != fontlist.end() &&
1134 (*tmp2).font == font) {
1135 // Put the position under the font
1141 // Add a new entry in the
1142 // fontlist for the position
1145 ft.pos_end = (*tmp).pos_end;
1146 ft.font = (*tmp).font;
1147 (*tmp).pos_end = pos;
1149 fontlist.insert(fontlist.begin(), ft);
1150 } else if (pos == (*tmp).pos_end) {
1151 // Add a new entry in the
1152 // fontlist for the position
1154 ft.pos = (*tmp).pos;
1155 ft.pos_end = (*tmp).pos_end - 1;
1156 ft.font = (*tmp).font;
1157 (*tmp).pos = (*tmp).pos_end;
1159 fontlist.insert(fontlist.begin(), ft);
1161 // Add a new entry in the
1162 // fontlist for the position
1164 ft.pos = (*tmp).pos;
1165 ft.pos_end = pos - 1;
1166 ft.font = (*tmp).font;
1170 ft2.pos_end = (*tmp).pos_end;
1171 ft2.font = (*tmp).font;
1174 (*tmp).pos_end = pos;
1177 fontlist.insert(fontlist.begin(), ft);
1178 fontlist.insert(fontlist.begin(), ft2);
1186 // This function is able to hide closed footnotes.
1187 LyXParagraph * LyXParagraph::Next()
1189 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1190 LyXParagraph * tmp = next;
1192 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1194 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1195 return tmp->Next(); /* there can be more than one
1196 footnote in a logical
1199 return next; // This should never happen!
1205 LyXParagraph * LyXParagraph::NextAfterFootnote()
1207 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1208 LyXParagraph * tmp = next;
1209 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1211 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1212 return tmp; /* there can be more than one footnote
1213 in a logical paragraph */
1215 return next; // This should never happen!
1221 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1223 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1224 LyXParagraph * tmp = next;
1225 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1227 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1228 return tmp; /* there can be more than one footnote
1229 in a logical paragraph */
1231 return next; // This should never happen!
1237 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1240 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1242 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1243 tmp = tmp->previous;
1244 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1245 return tmp; /* there can be more than one footnote
1246 in a logical paragraph */
1248 return previous; // This should never happen!
1254 LyXParagraph * LyXParagraph::LastPhysicalPar()
1256 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1259 LyXParagraph * tmp = this;
1261 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1262 tmp = tmp->NextAfterFootnote();
1267 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1269 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1272 LyXParagraph const * tmp = this;
1274 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1275 tmp = tmp->NextAfterFootnote();
1280 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1284 LyXParagraph * tmppar = this;
1288 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1289 tmppar = tmppar->previous;
1298 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1302 LyXParagraph const * tmppar = this;
1306 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1307 tmppar = tmppar->previous;
1316 // This function is able to hide closed footnotes.
1317 LyXParagraph * LyXParagraph::Previous()
1319 LyXParagraph * tmp = previous;
1324 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1325 tmp = tmp->previous;
1327 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1328 tmp = tmp->previous;
1329 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1330 return tmp->next->Previous();
1339 // This function is able to hide closed footnotes.
1340 LyXParagraph const * LyXParagraph::Previous() const
1342 LyXParagraph * tmp = previous;
1347 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1348 tmp = tmp->previous;
1350 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1351 tmp = tmp->previous;
1352 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1353 return tmp->next->Previous();
1362 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1365 size_type i, j, pos_end, pos_first;
1366 // create a new paragraph
1367 LyXParagraph * par = ParFromPos(pos);
1368 LyXParagraph * firstpar = FirstPhysicalPar();
1370 LyXParagraph * tmp = new LyXParagraph(par);
1372 tmp->footnoteflag = footnoteflag;
1373 tmp->footnotekind = footnotekind;
1375 // this is an idea for a more userfriendly layout handling, I will
1376 // see what the users say
1378 // layout stays the same with latex-environments
1380 tmp->SetOnlyLayout(firstpar->layout);
1381 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1384 if (Last() > pos || !Last() || flag == 2) {
1385 tmp->SetOnlyLayout(firstpar->layout);
1386 tmp->align = firstpar->align;
1387 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1389 tmp->line_bottom = firstpar->line_bottom;
1390 firstpar->line_bottom = false;
1391 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1392 firstpar->pagebreak_bottom = false;
1393 tmp->added_space_bottom = firstpar->added_space_bottom;
1394 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1396 tmp->depth = firstpar->depth;
1397 tmp->noindent = firstpar->noindent;
1399 // copy everything behind the break-position
1400 // to the new paragraph
1402 while (ParFromPos(pos_first) != par)
1405 pos_end = pos_first + par->text.size() - 1;
1407 for (i = j = pos; i <= pos_end; ++i) {
1408 par->CutIntoMinibuffer(i - pos_first);
1409 if (tmp->InsertFromMinibuffer(j - pos))
1412 tmp->text.resize(tmp->text.size());
1413 for (i = pos_end; i >= pos; --i)
1414 par->Erase(i - pos_first);
1416 par->text.resize(par->text.size());
1419 // just an idea of me
1421 tmp->line_top = firstpar->line_top;
1422 tmp->pagebreak_top = firstpar->pagebreak_top;
1423 tmp->added_space_top = firstpar->added_space_top;
1424 tmp->bibkey = firstpar->bibkey;
1426 // layout stays the same with latex-environments
1428 firstpar->SetOnlyLayout(tmp->layout);
1429 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1430 firstpar->depth = tmp->depth;
1436 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1438 par = par->FirstPhysicalPar();
1439 footnoteflag = par->footnoteflag;
1440 footnotekind = par->footnotekind;
1442 layout = par->layout;
1443 align = par-> align;
1444 SetLabelWidthString(par->labelwidthstring);
1446 line_bottom = par->line_bottom;
1447 pagebreak_bottom = par->pagebreak_bottom;
1448 added_space_bottom = par->added_space_bottom;
1450 line_top = par->line_top;
1451 pagebreak_top = par->pagebreak_top;
1452 added_space_top = par->added_space_top;
1454 spacing = par->spacing;
1456 pextra_type = par->pextra_type;
1457 pextra_width = par->pextra_width;
1458 pextra_widthp = par->pextra_widthp;
1459 pextra_alignment = par->pextra_alignment;
1460 pextra_hfill = par->pextra_hfill;
1461 pextra_start_minipage = par->pextra_start_minipage;
1463 noindent = par->noindent;
1468 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1470 LyXParagraph * tmppar = this;
1473 && tmppar->previous->footnoteflag ==
1474 LyXParagraph::CLOSED_FOOTNOTE)
1475 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1476 tmppar = tmppar->previous;
1479 return this; // This should never happen!
1485 LyXParagraph * LyXParagraph::Clone() const
1487 // create a new paragraph
1488 LyXParagraph * result = new LyXParagraph;
1490 result->MakeSameLayout(this);
1492 // this is because of the dummy layout of the paragraphs that
1494 result->layout = layout;
1496 /* table stuff -- begin*/
1498 result->table = table->Clone();
1501 /* table stuff -- end*/
1503 result->inset_owner = inset_owner;
1506 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1509 // copy everything behind the break-position to the new paragraph
1511 result->text = text;
1512 result->fontlist = fontlist;
1513 result->insetlist = insetlist;
1514 for (InsetList::iterator it = result->insetlist.begin();
1515 it != result->insetlist.end(); ++it)
1516 (*it).inset = (*it).inset->Clone();
1521 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1523 par = par->FirstPhysicalPar();
1526 par->footnoteflag == footnoteflag &&
1527 par->footnotekind == footnotekind &&
1529 par->layout == layout &&
1531 par->align == align &&
1533 par->line_bottom == line_bottom &&
1534 par->pagebreak_bottom == pagebreak_bottom &&
1535 par->added_space_bottom == added_space_bottom &&
1537 par->line_top == line_top &&
1538 par->pagebreak_top == pagebreak_top &&
1539 par->added_space_top == added_space_top &&
1541 par->spacing == spacing &&
1543 par->pextra_type == pextra_type &&
1544 par->pextra_width == pextra_width &&
1545 par->pextra_widthp == pextra_widthp &&
1546 par->pextra_alignment == pextra_alignment &&
1547 par->pextra_hfill == pextra_hfill &&
1548 par->pextra_start_minipage == pextra_start_minipage &&
1550 par->table == table && // what means: NO TABLE AT ALL
1552 par->noindent == noindent &&
1553 par->depth == depth);
1557 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1559 // create a new paragraph
1560 LyXParagraph * par = ParFromPos(pos);
1562 LyXParagraph * tmp = new LyXParagraph(par);
1564 tmp->MakeSameLayout(par);
1566 // When can pos < Last()?
1567 // I guess pos == Last() is possible.
1569 // copy everything behind the break-position to the new
1571 size_type pos_first = 0;
1572 while (ParFromPos(pos_first) != par)
1574 size_type pos_end = pos_first + par->text.size() - 1;
1577 for (i = j = pos; i <= pos_end; ++i) {
1578 par->CutIntoMinibuffer(i - pos_first);
1579 if (tmp->InsertFromMinibuffer(j - pos))
1582 tmp->text.resize(tmp->text.size());
1583 for (size_type i = pos_end; i >= pos; --i)
1584 par->Erase(i - pos_first);
1586 par->text.resize(par->text.size());
1591 // Be carefull, this does not make any check at all.
1592 void LyXParagraph::PasteParagraph()
1594 // copy the next paragraph to this one
1595 LyXParagraph * the_next = Next();
1597 LyXParagraph * firstpar = FirstPhysicalPar();
1599 // first the DTP-stuff
1600 firstpar->line_bottom = the_next->line_bottom;
1601 firstpar->added_space_bottom = the_next->added_space_bottom;
1602 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1604 size_type pos_end = the_next->text.size() - 1;
1605 size_type pos_insert = Last();
1607 // ok, now copy the paragraph
1609 for (i = j = 0; i <= pos_end; ++i) {
1610 the_next->CutIntoMinibuffer(i);
1611 if (InsertFromMinibuffer(pos_insert + j))
1615 // delete the next paragraph
1620 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1622 LyXParagraph * par = ParFromPos(pos);
1624 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1625 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1631 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1633 LyXParagraph * par = ParFromPos(pos);
1635 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1636 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1641 int LyXParagraph::GetEndLabel() const
1643 LyXParagraph const * par = this;
1644 int par_depth = GetDepth();
1646 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1648 textclasslist.Style(current_view->buffer()->params.textclass,
1649 layout).endlabeltype;
1650 if (endlabeltype != END_LABEL_NO_LABEL) {
1651 LyXParagraph const * last = this;
1652 if( footnoteflag == NO_FOOTNOTE)
1653 last = LastPhysicalPar();
1654 else if (next->footnoteflag == NO_FOOTNOTE)
1655 return endlabeltype;
1657 if (!last || !last->next)
1658 return endlabeltype;
1660 int next_depth = last->next->GetDepth();
1661 if (par_depth > next_depth ||
1662 (par_depth == next_depth && layout != last->next->GetLayout() ))
1663 return endlabeltype;
1668 par = par->DepthHook(par_depth - 1);
1670 par_depth = par->GetDepth();
1672 return END_LABEL_NO_LABEL;
1676 LyXTextClass::size_type LyXParagraph::GetLayout() const
1678 return FirstPhysicalPar()->layout;
1682 char LyXParagraph::GetDepth() const
1684 return FirstPhysicalPar()->depth;
1688 char LyXParagraph::GetAlign() const
1690 return FirstPhysicalPar()->align;
1694 string LyXParagraph::GetLabelstring() const
1696 return FirstPhysicalPar()->labelstring;
1700 int LyXParagraph::GetFirstCounter(int i) const
1702 return FirstPhysicalPar()->counter_[i];
1706 // the next two functions are for the manual labels
1707 string LyXParagraph::GetLabelWidthString() const
1709 if (!FirstPhysicalPar()->labelwidthstring.empty())
1710 return FirstPhysicalPar()->labelwidthstring;
1712 return _("Senseless with this layout!");
1716 void LyXParagraph::SetLabelWidthString(string const & s)
1718 LyXParagraph * par = FirstPhysicalPar();
1720 par->labelwidthstring = s;
1724 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1726 LyXParagraph * par = FirstPhysicalPar();
1727 LyXParagraph * ppar = 0;
1728 LyXParagraph * npar = 0;
1730 par->layout = new_layout;
1731 /* table stuff -- begin*/
1734 /* table stuff -- end*/
1735 if (par->pextra_type == PEXTRA_NONE) {
1736 if (par->Previous()) {
1737 ppar = par->Previous()->FirstPhysicalPar();
1740 && (ppar->depth > par->depth))
1741 ppar = ppar->Previous()->FirstPhysicalPar();
1744 npar = par->Next()->NextAfterFootnote();
1747 && (npar->depth > par->depth))
1748 npar = npar->Next()->NextAfterFootnote();
1750 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1752 p1 = ppar->pextra_width,
1753 p2 = ppar->pextra_widthp;
1754 ppar->SetPExtraType(ppar->pextra_type,
1755 p1.c_str(), p2.c_str());
1757 if ((par->pextra_type == PEXTRA_NONE) &&
1758 npar && (npar->pextra_type != PEXTRA_NONE)) {
1760 p1 = npar->pextra_width,
1761 p2 = npar->pextra_widthp;
1762 npar->SetPExtraType(npar->pextra_type,
1763 p1.c_str(), p2.c_str());
1769 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1772 * par = FirstPhysicalPar(),
1776 par->layout = new_layout;
1777 par->labelwidthstring.clear();
1778 par->align = LYX_ALIGN_LAYOUT;
1779 par->added_space_top = VSpace(VSpace::NONE);
1780 par->added_space_bottom = VSpace(VSpace::NONE);
1781 par->spacing.set(Spacing::Default);
1783 /* table stuff -- begin*/
1786 /* table stuff -- end*/
1787 if (par->pextra_type == PEXTRA_NONE) {
1788 if (par->Previous()) {
1789 ppar = par->Previous()->FirstPhysicalPar();
1792 && (ppar->depth > par->depth))
1793 ppar = ppar->Previous()->FirstPhysicalPar();
1796 npar = par->Next()->NextAfterFootnote();
1799 && (npar->depth > par->depth))
1800 npar = npar->Next()->NextAfterFootnote();
1802 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1804 p1 = ppar->pextra_width,
1805 p2 = ppar->pextra_widthp;
1806 ppar->SetPExtraType(ppar->pextra_type,
1807 p1.c_str(), p2.c_str());
1809 if ((par->pextra_type == PEXTRA_NONE) &&
1810 npar && (npar->pextra_type != PEXTRA_NONE)) {
1812 p1 = npar->pextra_width,
1813 p2 = npar->pextra_widthp;
1814 npar->SetPExtraType(npar->pextra_type,
1815 p1.c_str(), p2.c_str());
1821 // if the layout of a paragraph contains a manual label, the beginning of the
1822 // main body is the beginning of the second word. This is what the par-
1823 // function returns. If the layout does not contain a label, the main
1824 // body always starts with position 0. This differentiation is necessary,
1825 // because there cannot be a newline or a blank <= the beginning of the
1826 // main body in TeX.
1828 int LyXParagraph::BeginningOfMainBody() const
1830 if (FirstPhysicalPar() != this)
1833 // Unroll the first two cycles of the loop
1834 // and remember the previous character to
1835 // remove unnecessary GetChar() calls
1838 && GetChar(i) != LyXParagraph::META_NEWLINE
1841 char previous_char = 0, temp = 0;
1843 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1844 // Yes, this ^ is supposed to be "= " not "=="
1847 && previous_char != ' '
1848 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1850 previous_char = temp;
1855 if (i == 0 && i == size() &&
1856 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1857 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1858 ++i; /* the cursor should not jump
1859 * to the main body if there
1865 LyXParagraph * LyXParagraph::DepthHook(int deth)
1867 LyXParagraph * newpar = this;
1872 newpar = newpar->FirstPhysicalPar()->Previous();
1873 } while (newpar && newpar->GetDepth() > deth
1874 && newpar->footnoteflag == footnoteflag);
1877 if (Previous() || GetDepth())
1878 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1882 return newpar->FirstPhysicalPar();
1886 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1888 LyXParagraph const * newpar = this;
1893 newpar = newpar->FirstPhysicalPar()->Previous();
1894 } while (newpar && newpar->GetDepth() > deth
1895 && newpar->footnoteflag == footnoteflag);
1898 if (Previous() || GetDepth())
1899 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1903 return newpar->FirstPhysicalPar();
1907 int LyXParagraph::AutoDeleteInsets()
1910 InsetList::size_type index = 0;
1911 while (index < insetlist.size()) {
1912 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1913 Erase(insetlist[index].pos);
1914 // Erase() calls to insetlist.erase(&insetlist[index])
1915 // so index shouldn't be increased.
1924 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1926 InsetList::iterator it = lower_bound(insetlist.begin(),
1929 if (it != insetlist.end()) {
1937 // returns -1 if inset not found
1938 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1941 // We could use lower_bound here too, we just need to add
1942 // the approp. operator() to matchIT (and change the name
1943 // of that struct). Code would then be:
1944 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1946 // inset, matchIT());
1947 // if ((*cit).inset == inset) {
1948 // return (*cit).pos;
1950 for (InsetList::const_iterator cit = insetlist.begin();
1951 cit != insetlist.end(); ++cit) {
1952 if ((*cit).inset == inset) {
1956 // Think about footnotes.
1957 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1958 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1960 NextAfterFootnote()->GetPositionOfInset(inset);
1962 return text.size() + 1 + further;
1968 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1970 TexRow & foot_texrow,
1973 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1974 LyXLayout const & style =
1975 textclasslist.Style(current_view->buffer()->params.textclass,
1978 bool further_blank_line = false;
1980 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1982 if (start_of_appendix) {
1983 os << "\\appendix\n";
1987 if (!spacing.isDefault()
1988 && (!Previous() || !Previous()->HasSameLayout(this))) {
1989 os << "\\begin{spacing}{"
1990 << spacing.getValue() << "}\n";
1994 if (tex_code_break_column && style.isCommand()){
1999 if (pagebreak_top) {
2001 further_blank_line = true;
2003 if (added_space_top.kind() != VSpace::NONE) {
2004 os << added_space_top.asLatexCommand(current_view->buffer()->params);
2005 further_blank_line = true;
2009 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2010 << "\\vspace{-1\\parskip}";
2011 further_blank_line = true;
2014 if (further_blank_line){
2019 Language const * language = getParLanguage();
2020 Language const * doc_language = current_view->buffer()->params.language_info;
2021 if (language != doc_language) {
2022 os << subst(lyxrc.language_command_begin, "$$lang",
2028 switch (style.latextype) {
2031 << style.latexname()
2032 << style.latexparam();
2034 case LATEX_ITEM_ENVIRONMENT:
2036 bibkey->Latex(os, false, false);
2040 case LATEX_LIST_ENVIRONMENT:
2047 bool need_par = SimpleTeXOnePar(os, texrow);
2049 // Spit out footnotes
2050 LyXParagraph * par = next;
2051 if (lyxrc.rtl_support) {
2052 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2053 && next->footnoteflag != footnoteflag) {
2054 LyXParagraph * p = 0;
2055 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2056 if ( (p = NextAfterFootnote()) != 0 &&
2057 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2058 is_rtl = GetFontSettings(0).isRightToLeft();
2060 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2061 par->footnoteflag != footnoteflag) {
2062 par = par->TeXFootnote(os, texrow, foot,
2063 foot_texrow, foot_count,
2065 par->SimpleTeXOnePar(os, texrow);
2066 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2068 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2069 (p = par->NextAfterFootnote()) != 0 &&
2070 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2071 is_rtl = GetFontSettings(0).isRightToLeft();
2076 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2077 && par->footnoteflag != footnoteflag) {
2078 par = par->TeXFootnote(os, texrow,
2079 foot, foot_texrow, foot_count,
2081 par->SimpleTeXOnePar(os, texrow);
2086 // Make sure that \\par is done with the font of the last
2087 // character if this has another size as the default.
2088 // This is necessary because LaTeX (and LyX on the screen)
2089 // calculates the space between the baselines according
2090 // to this font. (Matthias)
2091 LyXFont font = getFont(Last() - 1);
2093 if (style.resfont.size() != font.size()) {
2099 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2100 GetLayout()).isCommand()){
2101 if (style.resfont.size() != font.size()) {
2107 } else if (style.resfont.size() != font.size()){
2108 os << "{\\" << font.latexSize() << " \\par}";
2111 if (language != doc_language) {
2113 << subst(lyxrc.language_command_end, "$$lang",
2114 doc_language->lang);
2117 switch (style.latextype) {
2118 case LATEX_ITEM_ENVIRONMENT:
2119 case LATEX_LIST_ENVIRONMENT:
2120 if (par && (depth < par->depth)) {
2125 case LATEX_ENVIRONMENT:
2126 // if its the last paragraph of the current environment
2127 // skip it otherwise fall through
2129 && (par->layout != layout
2130 || par->depth != depth
2131 || par->pextra_type != pextra_type))
2134 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2135 && footnotekind != LyXParagraph::FOOTNOTE
2136 && footnotekind != LyXParagraph::MARGIN
2140 // don't insert this if we would be adding it
2141 // before or after a table in a float. This
2142 // little trick is needed in order to allow
2143 // use of tables in \subfigures or \subtables.
2149 further_blank_line = false;
2151 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2152 further_blank_line = true;
2155 if (added_space_bottom.kind() != VSpace::NONE) {
2156 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2157 further_blank_line = true;
2160 if (pagebreak_bottom) {
2162 further_blank_line = true;
2165 if (further_blank_line){
2170 if (!spacing.isDefault()
2171 && (!par || !par->HasSameLayout(this))) {
2172 os << "\\end{spacing}\n";
2176 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2177 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2182 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2187 // This one spits out the text of the paragraph
2188 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2190 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2193 return SimpleTeXOneTablePar(os, texrow);
2195 bool return_value = false;
2197 LyXLayout const & style =
2198 textclasslist.Style(current_view->buffer()->params.textclass,
2200 LyXFont basefont, last_font;
2202 // Maybe we have to create a optional argument.
2203 size_type main_body;
2204 if (style.labeltype != LABEL_MANUAL)
2207 main_body = BeginningOfMainBody();
2209 if (main_body > 0) {
2211 basefont = getFont(-2); // Get label font
2213 basefont = getFont(-1); // Get layout font
2221 if (style.isCommand()) {
2224 } else if (align != LYX_ALIGN_LAYOUT) {
2227 return_value = true;
2231 // Which font is currently active?
2232 LyXFont running_font(basefont);
2233 // Do we have an open font change?
2234 bool open_font = false;
2236 texrow.start(this, 0);
2238 for (size_type i = 0; i < size(); ++i) {
2240 // First char in paragraph or after label?
2241 if (i == main_body && !IsDummy()) {
2242 if (main_body > 0) {
2244 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2247 basefont = getFont(-1); // Now use the layout font
2248 running_font = basefont;
2252 if (style.isCommand()) {
2255 } else if (align != LYX_ALIGN_LAYOUT) {
2258 return_value = true;
2262 os << "\\noindent ";
2266 case LYX_ALIGN_NONE:
2267 case LYX_ALIGN_BLOCK:
2268 case LYX_ALIGN_LAYOUT:
2269 case LYX_ALIGN_SPECIAL:
2271 case LYX_ALIGN_LEFT:
2272 if (getParLanguage()->lang != "hebrew") {
2273 os << "\\raggedright ";
2276 os << "\\raggedleft ";
2280 case LYX_ALIGN_RIGHT:
2281 if (getParLanguage()->lang != "hebrew") {
2282 os << "\\raggedleft ";
2285 os << "\\raggedright ";
2289 case LYX_ALIGN_CENTER:
2290 os << "\\centering ";
2298 // Fully instantiated font
2299 LyXFont font = getFont(i);
2300 LyXParagraph * p = 0;
2301 if (i == 0 && previous &&
2302 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2303 (p = PreviousBeforeFootnote()) != 0)
2304 last_font = p->getFont(p->size()-1);
2306 last_font = running_font;
2308 // Spaces at end of font change are simulated to be
2309 // outside font change, i.e. we write "\textXX{text} "
2310 // rather than "\textXX{text }". (Asger)
2311 if (open_font && c == ' ' && i <= size() - 2
2312 && !getFont(i+1).equalExceptLatex(running_font)
2313 && !getFont(i+1).equalExceptLatex(font)) {
2314 font = getFont(i + 1);
2316 // We end font definition before blanks
2317 if (!font.equalExceptLatex(running_font) && open_font) {
2318 column += running_font.latexWriteEndChanges(os,
2320 (i == main_body-1) ? basefont : font);
2321 running_font = basefont;
2325 // Blanks are printed before start of fontswitch
2327 // Do not print the separation of the optional argument
2328 if (i != main_body - 1) {
2329 SimpleTeXBlanks(os, texrow, i,
2330 column, font, style);
2334 // Do we need to change font?
2335 if (!font.equalExceptLatex(running_font)
2336 && i != main_body-1) {
2337 column += font.latexWriteStartChanges(os, basefont,
2339 running_font = font;
2343 if (c == LyXParagraph::META_NEWLINE) {
2344 // newlines are handled differently here than
2345 // the default in SimpleTeXSpecialChars().
2346 if (!style.newline_allowed
2347 || font.latex() == LyXFont::ON) {
2351 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2354 basefont = getFont(-1);
2355 running_font = basefont;
2356 if (font.family() ==
2357 LyXFont::TYPEWRITER_FAMILY) {
2363 texrow.start(this, i + 1);
2366 SimpleTeXSpecialChars(os, texrow,
2367 font, running_font, basefont,
2368 open_font, style, i, column, c);
2372 // If we have an open font definition, we have to close it
2374 LyXParagraph * p = 0;
2375 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2376 && (p = NextAfterFootnote()) != 0)
2377 running_font.latexWriteEndChanges(os, basefont,
2380 running_font.latexWriteEndChanges(os, basefont, basefont);
2383 // Needed if there is an optional argument but no contents.
2384 if (main_body > 0 && main_body == size()) {
2386 return_value = false;
2389 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2390 return return_value;
2394 // This one spits out the text of a table paragraph
2395 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2397 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2399 bool return_value = false;
2401 LyXLayout const & style =
2402 textclasslist.Style(current_view->buffer()->params.textclass,
2406 if (!IsDummy()) { // it is dummy if it is in a float!!!
2407 if (style.isCommand()) {
2410 } else if (align != LYX_ALIGN_LAYOUT) {
2413 return_value = true;
2416 os << "\\noindent ";
2420 case LYX_ALIGN_NONE:
2421 case LYX_ALIGN_BLOCK:
2422 case LYX_ALIGN_LAYOUT:
2423 case LYX_ALIGN_SPECIAL: break;
2424 case LYX_ALIGN_LEFT:
2425 os << "\\raggedright ";
2428 case LYX_ALIGN_RIGHT:
2429 os << "\\raggedleft ";
2432 case LYX_ALIGN_CENTER:
2433 os << "\\centering ";
2439 LyXFont basefont = getFont(-1); // Get layout font
2440 // Which font is currently active?
2441 LyXFont running_font = basefont;
2443 // Do we have an open font change?
2444 bool open_font = false;
2445 int current_cell_number = -1;
2446 int tmp = table->TexEndOfCell(os, current_cell_number);
2447 for (; tmp > 0 ; --tmp)
2450 texrow.start(this, 0);
2452 bool is_rtl = getParLanguage()->RightToLeft;
2453 bool first_in_cell = true;
2455 for (size_type i = 0; i < size(); ++i) {
2456 char c = GetChar(i);
2457 if (table->IsContRow(current_cell_number + 1)) {
2458 if (c == LyXParagraph::META_NEWLINE)
2459 ++current_cell_number;
2464 if (first_in_cell && is_rtl) {
2467 first_in_cell = false;
2470 // Fully instantiated font
2471 LyXFont font = getFont(i);
2472 last_font = running_font;
2474 // Spaces at end of font change are simulated to be
2475 // outside font change.
2476 // i.e. we write "\textXX{text} " rather than
2477 // "\textXX{text }". (Asger)
2478 if (open_font && c == ' ' && i <= size() - 2
2479 && getFont(i + 1) != running_font
2480 && getFont(i + 1) != font) {
2481 font = getFont(i + 1);
2484 // We end font definition before blanks
2485 if (font != running_font && open_font) {
2486 column += running_font.latexWriteEndChanges(os,
2489 running_font = basefont;
2492 // Blanks are printed before start of fontswitch
2494 SimpleTeXBlanks(os, texrow, i, column, font, style);
2496 // Do we need to change font?
2497 if (font != running_font) {
2498 column += font.latexWriteStartChanges(os, basefont,
2500 running_font = font;
2503 // Do we need to turn on LaTeX mode?
2504 if (font.latex() != running_font.latex()) {
2505 if (font.latex() == LyXFont::ON
2506 && style.needprotect) {
2511 if (c == LyXParagraph::META_NEWLINE) {
2512 // special case for inside a table
2513 // different from default case in
2514 // SimpleTeXSpecialChars()
2516 column += running_font
2517 .latexWriteEndChanges(os, basefont,
2521 basefont = getFont(-1);
2522 running_font = basefont;
2523 ++current_cell_number;
2524 if (table->CellHasContRow(current_cell_number) >= 0) {
2525 TeXContTableRows(os, i + 1,
2526 current_cell_number,
2529 if (is_rtl && !first_in_cell) {
2531 first_in_cell = true;
2534 // if this cell follow only ContRows till end don't
2535 // put the EndOfCell because it is put after the
2537 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2538 --current_cell_number;
2541 int tmp = table->TexEndOfCell(os,
2542 current_cell_number);
2545 } else if (tmp < 0) {
2551 texrow.start(this, i + 1);
2553 SimpleTeXSpecialChars(os, texrow,
2554 font, running_font, basefont,
2555 open_font, style, i, column, c);
2559 // If we have an open font definition, we have to close it
2561 running_font.latexWriteEndChanges(os, basefont, basefont);
2563 ++current_cell_number;
2564 if (is_rtl && !first_in_cell)
2566 tmp = table->TexEndOfCell(os, current_cell_number);
2567 for (; tmp > 0; --tmp)
2569 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2570 return return_value;
2574 // This one spits out the text off ContRows in tables
2575 bool LyXParagraph::TeXContTableRows(ostream & os,
2576 LyXParagraph::size_type i,
2577 int current_cell_number,
2578 int & column, TexRow & texrow)
2580 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2586 bool return_value = false;
2587 LyXLayout const & style =
2588 textclasslist.Style(current_view->buffer()->params.textclass,
2590 LyXFont basefont = getFont(-1); // Get layout font
2592 // Which font is currently active?
2593 LyXFont running_font = basefont;
2594 // Do we have an open font change?
2595 bool open_font = false;
2597 size_type lastpos = i;
2598 int cell = table->CellHasContRow(current_cell_number);
2599 ++current_cell_number;
2601 // first find the right position
2603 for (; (i < size()) && (current_cell_number<cell); ++i) {
2605 if (c == LyXParagraph::META_NEWLINE)
2606 ++current_cell_number;
2610 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2614 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2619 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2623 // Fully instantiated font
2624 LyXFont font = getFont(i);
2625 last_font = running_font;
2627 // Spaces at end of font change are simulated to
2628 // be outside font change. i.e. we write
2629 // "\textXX{text} " rather than "\textXX{text }".
2631 if (open_font && c == ' ' && i <= size() - 2
2632 && getFont(i + 1) != running_font
2633 && getFont(i + 1) != font) {
2634 font = getFont(i + 1);
2637 // We end font definition before blanks
2638 if (font != running_font && open_font) {
2639 column += running_font.latexWriteEndChanges(os, basefont, font);
2640 running_font = basefont;
2643 // Blanks are printed before start of fontswitch
2645 SimpleTeXBlanks(os, texrow, i,
2646 column, font, style);
2648 // Do we need to change font?
2649 if (font != running_font) {
2651 font.latexWriteStartChanges(os,
2654 running_font = font;
2657 // Do we need to turn on LaTeX mode?
2658 if (font.latex() != running_font.latex()) {
2659 if (font.latex() == LyXFont::ON
2660 && style.needprotect) {
2665 SimpleTeXSpecialChars(os, texrow, font,
2666 running_font, basefont,
2667 open_font, style, i, column, c);
2669 // If we have an open font definition, we have to close it
2671 running_font.latexWriteEndChanges(os, basefont,
2675 basefont = getFont(-1);
2676 running_font = basefont;
2677 cell = table->CellHasContRow(current_cell_number);
2679 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2680 return return_value;
2684 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2686 bool retval = false;
2688 case LyXParagraph::META_HFILL:
2689 sgml_string.clear();
2692 case LyXParagraph::META_PROTECTED_SEPARATOR:
2696 case LyXParagraph::META_NEWLINE:
2700 sgml_string = "&";
2703 sgml_string = "<";
2706 sgml_string = ">";
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 = "\";
2742 case '\0': // Ignore :-)
2743 sgml_string.clear();
2753 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2754 int & desc_on, int depth)
2757 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2759 LyXFont font1, font2;
2762 size_type main_body;
2763 bool emph_flag = false;
2765 LyXLayout const & style =
2766 textclasslist.Style(current_view->buffer()->params.textclass,
2769 if (style.labeltype != LABEL_MANUAL)
2772 main_body = BeginningOfMainBody();
2774 // Gets paragraph main font.
2776 font1 = style.labelfont;
2780 int char_line_count = depth;
2781 os << newlineAndDepth(depth);
2782 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2783 os << "<INFORMALTABLE>"
2784 << newlineAndDepth(++depth);
2786 int current_cell_number = -1;
2787 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2789 // Parsing main loop.
2790 for (size_type i = 0; i < size(); ++i) {
2792 if (table->IsContRow(current_cell_number+1)) {
2793 if (c == LyXParagraph::META_NEWLINE)
2794 ++current_cell_number;
2799 // Fully instantiated font
2802 // Handle <emphasis> tag.
2803 if (font1.emph() != font2.emph() && i) {
2804 if (font2.emph() == LyXFont::ON) {
2807 } else if (emph_flag) {
2808 os << "</emphasis>";
2812 if (c == LyXParagraph::META_NEWLINE) {
2813 // We have only to control for emphasis open here!
2815 os << "</emphasis>";
2818 font1 = font2 = getFont(-1);
2819 ++current_cell_number;
2820 if (table->CellHasContRow(current_cell_number) >= 0) {
2821 DocBookContTableRows(os, extra, desc_on, i + 1,
2822 current_cell_number,
2825 // if this cell follow only ContRows till end don't
2826 // put the EndOfCell because it is put after the
2828 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2829 --current_cell_number;
2832 tmp = table->DocBookEndOfCell(os,
2833 current_cell_number,
2838 } else if (c == LyXParagraph::META_INSET) {
2839 inset = GetInset(i);
2841 std::ostringstream ost;
2842 inset->DocBook(ost);
2843 string tmp_out = ost.str().c_str();
2846 inset->DocBook(ost);
2848 char * ctmp = ost.str();
2849 string tmp_out(ctmp);
2853 // This code needs some explanation:
2854 // Two insets are treated specially
2855 // label if it is the first element in a
2856 // command paragraph
2858 // graphics inside tables or figure floats
2860 // title (the equivalente in latex for this
2862 // and title should come first
2865 if(desc_on != 3 || i != 0) {
2866 if(tmp_out[0] == '@') {
2868 extra += frontStrip(tmp_out,
2871 os << frontStrip(tmp_out,
2876 } else if (font2.latex() == LyXFont::ON) {
2877 // "TeX"-Mode on == > SGML-Mode on.
2883 if (linuxDocConvertChar(c, sgml_string)
2884 && !style.free_spacing) {
2885 // in freespacing mode, spaces are
2886 // non-breaking characters
2891 << "</term><listitem><para>";
2903 // Needed if there is an optional argument but no contents.
2904 if (main_body > 0 && main_body == size()) {
2909 os << "</emphasis>";
2912 ++current_cell_number;
2913 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2914 // Resets description flag correctly.
2917 // <term> not closed...
2921 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2922 os << "</INFORMALTABLE>";
2924 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2929 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2931 LyXParagraph::size_type i,
2932 int current_cell_number, int &column)
2937 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2942 //string emph = "emphasis";
2943 bool emph_flag = false;
2944 int char_line_count = 0;
2946 LyXLayout const & style =
2947 textclasslist.Style(current_view->buffer()->params.textclass,
2950 size_type main_body;
2951 if (style.labeltype != LABEL_MANUAL)
2954 main_body = BeginningOfMainBody();
2956 // Gets paragraph main font.
2959 font1 = style.labelfont;
2963 size_type lastpos = i;
2964 int cell = table->CellHasContRow(current_cell_number);
2965 ++current_cell_number;
2967 // first find the right position
2969 for (; i < size() && current_cell_number < cell; ++i) {
2971 if (c == LyXParagraph::META_NEWLINE)
2972 ++current_cell_number;
2976 // I don't know how to handle this so I comment it
2977 // for the moment (Jug)
2978 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2979 // file += " \\\\\n";
2982 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2987 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2991 // Fully instantiated font
2994 // Handle <emphasis> tag.
2995 if (font1.emph() != font2.emph() && i) {
2996 if (font2.emph() == LyXFont::ON) {
2999 } else if (emph_flag) {
3000 os << "</emphasis>";
3004 if (c == LyXParagraph::META_INSET) {
3005 inset = GetInset(i);
3007 std::ostringstream ost;
3008 inset->DocBook(ost);
3009 string tmp_out = ost.str().c_str();
3012 inset->DocBook(ost);
3014 char * ctmp = ost.str();
3015 string tmp_out(ctmp);
3019 // This code needs some explanation:
3020 // Two insets are treated specially
3021 // label if it is the first element in a
3022 // command paragraph
3024 // graphics inside tables or figure floats
3025 // can't go on title (the equivalente in
3026 // latex for this case is caption and title
3027 // should come first
3030 if(desc_on != 3 || i != 0) {
3031 if(tmp_out[0] == '@') {
3033 extra += frontStrip(tmp_out, '@');
3035 os << frontStrip(tmp_out, '@');
3039 } else if (font2.latex() == LyXFont::ON) {
3040 // "TeX"-Mode on == > SGML-Mode on.
3046 if (linuxDocConvertChar(c, sgml_string)
3047 && !style.free_spacing) {
3048 // in freespacing mode, spaces are
3049 // non-breaking characters
3054 << "</term><listitem><para>";
3064 // we have only to control for emphasis open here!
3066 os << "</emphasis>";
3069 font1 = font2 = getFont(-1);
3070 cell = table->CellHasContRow(current_cell_number);
3072 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3076 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3077 LyXParagraph::size_type const i,
3078 int & column, LyXFont const & font,
3079 LyXLayout const & style)
3081 if (column > tex_code_break_column
3083 && GetChar(i - 1) != ' '
3085 // In LaTeX mode, we don't want to
3086 // break lines since some commands
3088 && ! (font.latex() == LyXFont::ON)
3089 // same in FreeSpacing mode
3090 && !style.free_spacing
3091 // In typewriter mode, we want to avoid
3092 // ! . ? : at the end of a line
3093 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3094 && (GetChar(i-1) == '.'
3095 || GetChar(i-1) == '?'
3096 || GetChar(i-1) == ':'
3097 || GetChar(i-1) == '!'))) {
3098 if (tex_code_break_column == 0) {
3099 // in batchmode we need LaTeX to still
3100 // see it as a space not as an extra '\n'
3106 texrow.start(this, i + 1);
3108 } else if (font.latex() == LyXFont::OFF) {
3109 if (style.free_spacing) {
3118 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3120 LyXFont & running_font,
3123 LyXLayout const & style,
3124 LyXParagraph::size_type & i,
3125 int & column, char const c)
3127 // Two major modes: LaTeX or plain
3128 // Handle here those cases common to both modes
3129 // and then split to handle the two modes separately.
3131 case LyXParagraph::META_INSET: {
3132 Inset * inset = GetInset(i);
3135 int len = os.tellp();
3136 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3137 || inset->LyxCode() == Inset::MATH_CODE
3138 || inset->LyxCode() == Inset::URL_CODE)
3139 && running_font.isRightToLeft()) {
3142 } else if (inset->LyxCode() == Inset::NUMBER_CODE
3143 && running_font.isRightToLeft()) {
3148 int tmp = inset->Latex(os, style.isCommand(),
3149 style.free_spacing);
3152 if (inset->LyxCode() == Inset::NUMBER_CODE)
3160 column += os.tellp() - len;
3169 case LyXParagraph::META_NEWLINE:
3171 column += running_font.latexWriteEndChanges(os,
3176 basefont = getFont(-1);
3177 running_font = basefont;
3180 case LyXParagraph::META_HFILL:
3186 // And now for the special cases within each mode
3187 // Are we in LaTeX mode?
3188 if (font.latex() == LyXFont::ON) {
3189 // at present we only have one option
3190 // but I'll leave it as a switch statement
3191 // so its simpler to extend. (ARRae)
3194 case LyXParagraph::META_PROTECTED_SEPARATOR:
3199 // make sure that we will not print
3200 // error generating chars to the tex
3201 // file. This test would not be needed
3202 // if it were done in the buffer
3210 // Plain mode (i.e. not LaTeX)
3213 case LyXParagraph::META_PROTECTED_SEPARATOR:
3218 os << "\\textbackslash{}";
3222 case '°': case '±': case '²': case '³':
3223 case '×': case '÷': case '¹': case 'ª':
3224 case 'º': case '¬': case 'µ':
3225 if (current_view->buffer()->params.inputenc == "latin1") {
3226 os << "\\ensuremath{"
3235 case '|': case '<': case '>':
3236 // In T1 encoding, these characters exist
3237 if (lyxrc.fontenc == "T1") {
3239 //... but we should avoid ligatures
3240 if ((c == '>' || c == '<')
3242 && GetChar(i + 1) == c){
3243 os << "\\textcompwordmark{}";
3248 // Typewriter font also has them
3249 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3253 // Otherwise, we use what LaTeX
3257 os << "\\textless{}";
3261 os << "\\textgreater{}";
3265 os << "\\textbar{}";
3271 case '-': // "--" in Typewriter mode -> "-{}-"
3273 && GetChar(i + 1) == '-'
3274 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3283 os << "\\char`\\\"{}";
3288 if (current_view->buffer()->params.inputenc == "default") {
3297 case '%': case '#': case '{':
3304 os << "\\textasciitilde{}";
3309 os << "\\textasciicircum{}";
3313 case '*': case '[': case ']':
3314 // avoid being mistaken for optional arguments
3315 os << '{' << c << '}';
3320 // Blanks are printed before font switching.
3321 // Sure? I am not! (try nice-latex)
3322 // I am sure it's correct. LyX might be smarter
3323 // in the future, but for now, nothing wrong is
3328 /* idea for labels --- begin*/
3332 && font.family() != LyXFont::TYPEWRITER_FAMILY
3333 && GetChar(i + 1) == 'y'
3334 && GetChar(i + 2) == 'X') {
3342 && font.family() != LyXFont::TYPEWRITER_FAMILY
3343 && GetChar(i + 1) == 'e'
3344 && GetChar(i + 2) == 'X') {
3349 // Check for "LaTeX2e"
3352 && font.family() != LyXFont::TYPEWRITER_FAMILY
3353 && GetChar(i + 1) == 'a'
3354 && GetChar(i + 2) == 'T'
3355 && GetChar(i + 3) == 'e'
3356 && GetChar(i + 4) == 'X'
3357 && GetChar(i + 5) == '2'
3358 && GetChar(i + 6) == 'e') {
3363 // Check for "LaTeX"
3366 && font.family() != LyXFont::TYPEWRITER_FAMILY
3367 && GetChar(i + 1) == 'a'
3368 && GetChar(i + 2) == 'T'
3369 && GetChar(i + 3) == 'e'
3370 && GetChar(i + 4) == 'X') {
3374 /* idea for labels --- end*/
3375 } else if (c != '\0') {
3386 bool LyXParagraph::RoffContTableRows(ostream & os,
3387 LyXParagraph::size_type i,
3393 LyXFont font1(LyXFont::ALL_INHERIT);
3398 string fname2 = TmpFileName(string(), "RAT2");
3400 int cell = table->CellHasContRow(actcell);
3403 // first find the right position
3405 for (; i < size() && actcell < cell; ++i) {
3407 if (c == LyXParagraph::META_NEWLINE)
3412 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3415 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3417 font2 = GetFontSettings(i);
3418 if (font1.latex() != font2.latex()) {
3419 if (font2.latex() != LyXFont::OFF)
3424 case LyXParagraph::META_INSET:
3425 if ((inset = GetInset(i))) {
3428 stringstream ss(ios::in | ios::out);
3429 inset->Latex(ss, -1);
3441 inset->Latex(ss, -1);
3454 fstream fs(fname2.c_str(),
3457 WriteAlert(_("LYX_ERROR:"),
3458 _("Cannot open temporary file:"),
3462 inset->Latex(fs, -1);
3476 case LyXParagraph::META_NEWLINE:
3478 case LyXParagraph::META_HFILL:
3481 case LyXParagraph::META_PROTECTED_SEPARATOR:
3491 lyxerr.debug() << "RoffAsciiTable: "
3492 "NULL char in structure."
3497 cell = table->CellHasContRow(actcell);
3504 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3506 TexRow & foot_texrow,
3509 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3510 LyXParagraph * par = this;
3512 while (par && par->depth == depth) {
3514 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3515 if (textclasslist.Style(current_view->buffer()->params.textclass,
3516 par->layout).isEnvironment()
3517 || par->pextra_type != PEXTRA_NONE) {
3518 par = par->TeXEnvironment(os, texrow,
3522 par = par->TeXOnePar(os, texrow,
3527 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3533 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3535 TexRow & foot_texrow,
3538 bool eindent_open = false;
3539 bool foot_this_level = false;
3540 // flags when footnotetext should be appended to file.
3541 static bool minipage_open = false;
3542 static int minipage_open_depth = 0;
3543 char par_sep = current_view->buffer()->params.paragraph_separation;
3545 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3547 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3549 LyXLayout const & style =
3550 textclasslist.Style(current_view->buffer()->params.textclass,
3553 if (pextra_type == PEXTRA_INDENT) {
3554 if (!pextra_width.empty()) {
3555 os << "\\begin{LyXParagraphIndent}{"
3556 << pextra_width << "}\n";
3558 //float ib = atof(pextra_widthp.c_str())/100;
3559 // string can't handle floats at present (971109)
3560 // so I'll do a conversion by hand knowing that
3561 // the limits are 0.0 to 1.0. ARRae.
3562 os << "\\begin{LyXParagraphIndent}{";
3563 switch (pextra_widthp.length()) {
3575 os << "\\columnwidth}\n";
3578 eindent_open = true;
3580 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3581 if (pextra_hfill && Previous() &&
3582 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3583 os << "\\hfill{}\n";
3586 if (par_sep == BufferParams::PARSEP_INDENT) {
3587 os << "{\\setlength\\parindent{0pt}\n";
3590 os << "\\begin{minipage}";
3591 switch(pextra_alignment) {
3592 case MINIPAGE_ALIGN_TOP:
3595 case MINIPAGE_ALIGN_MIDDLE:
3598 case MINIPAGE_ALIGN_BOTTOM:
3602 if (!pextra_width.empty()) {
3603 os << '{' << pextra_width << "}\n";
3605 //float ib = atof(par->pextra_width.c_str())/100;
3606 // string can't handle floats at present
3607 // so I'll do a conversion by hand knowing that
3608 // the limits are 0.0 to 1.0. ARRae.
3610 switch (pextra_widthp.length()) {
3622 os << "\\columnwidth}\n";
3625 if (par_sep == BufferParams::PARSEP_INDENT) {
3626 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3629 minipage_open = true;
3630 minipage_open_depth = depth;
3633 #ifdef WITH_WARNINGS
3634 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3635 //I disabled it because it breaks when lists span on several
3638 if (style.isEnvironment()){
3639 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3640 #ifdef FANCY_FOOTNOTE_CODE
3641 if (foot_count < 0) {
3642 // flag that footnote[mark][text] should be
3643 // used for any footnotes from now on
3645 foot_this_level = true;
3648 os << "\\begin{" << style.latexname() << "}{"
3649 << labelwidthstring << "}\n";
3650 } else if (style.labeltype == LABEL_BIBLIO) {
3652 os << "\\begin{" << style.latexname() << "}{"
3653 << bibitemWidthest(current_view->painter())
3655 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3656 #ifdef FANCY_FOOTNOTE_CODE
3657 if (foot_count < 0) {
3658 // flag that footnote[mark][text] should be
3659 // used for any footnotes from now on
3661 foot_this_level = true;
3664 os << "\\begin{" << style.latexname() << '}'
3665 << style.latexparam() << '\n';
3667 os << "\\begin{" << style.latexname() << '}'
3668 << style.latexparam() << '\n';
3671 LyXParagraph * par = this;
3673 par = par->TeXOnePar(os, texrow,
3674 foot, foot_texrow, foot_count);
3676 if (minipage_open && par && !style.isEnvironment() &&
3677 (par->pextra_type == PEXTRA_MINIPAGE) &&
3678 par->pextra_start_minipage) {
3679 os << "\\end{minipage}\n";
3681 if (par_sep == BufferParams::PARSEP_INDENT) {
3685 minipage_open = false;
3687 if (par && par->depth > depth) {
3688 if (textclasslist.Style(current_view->buffer()->params.textclass,
3689 par->layout).isParagraph()
3692 // How to handle this? (Lgb)
3693 //&& !suffixIs(os, "\n\n")
3695 // There should be at least one '\n' already
3696 // but we need there to be two for Standard
3697 // paragraphs that are depth-increment'ed to be
3698 // output correctly. However, tables can
3699 // also be paragraphs so don't adjust them.
3702 // Will it ever harm to have one '\n' too
3703 // many? i.e. that we sometimes will have
3704 // three in a row. (Lgb)
3708 par = par->TeXDeeper(os, texrow,
3709 foot, foot_texrow, foot_count);
3711 if (par && par->layout == layout && par->depth == depth &&
3712 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3713 if (par->pextra_hfill && par->Previous() &&
3714 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3715 os << "\\hfill{}\n";
3718 if (par_sep == BufferParams::PARSEP_INDENT) {
3719 os << "{\\setlength\\parindent{0pt}\n";
3722 os << "\\begin{minipage}";
3723 switch(par->pextra_alignment) {
3724 case MINIPAGE_ALIGN_TOP:
3727 case MINIPAGE_ALIGN_MIDDLE:
3730 case MINIPAGE_ALIGN_BOTTOM:
3734 if (!par->pextra_width.empty()) {
3735 os << '{' << par->pextra_width << "}\n";
3737 //float ib = atof(par->pextra_widthp.c_str())/100;
3738 // string can't handle floats at present
3739 // so I'll do a conversion by hand knowing that
3740 // the limits are 0.0 to 1.0. ARRae.
3742 switch (par->pextra_widthp.length()) {
3747 os << "0." << par->pextra_widthp;
3750 os << "0.0" << par->pextra_widthp;
3752 os << "\\columnwidth}\n";
3755 if (par_sep == BufferParams::PARSEP_INDENT) {
3756 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3759 minipage_open = true;
3760 minipage_open_depth = par->depth;
3763 && par->layout == layout
3764 && par->depth == depth
3765 && par->pextra_type == pextra_type);
3767 if (style.isEnvironment()) {
3768 os << "\\end{" << style.latexname() << '}';
3769 // maybe this should go after the minipage closes?
3770 if (foot_this_level) {
3771 if (foot_count >= 1) {
3772 if (foot_count > 1) {
3773 os << "\\addtocounter{footnote}{-"
3778 texrow += foot_texrow;
3780 foot_texrow.reset();
3785 if (minipage_open && (minipage_open_depth == depth) &&
3786 (!par || par->pextra_start_minipage ||
3787 par->pextra_type != PEXTRA_MINIPAGE)) {
3788 os << "\\end{minipage}\n";
3790 if (par_sep == BufferParams::PARSEP_INDENT) {
3794 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3795 os << "\\medskip\n\n";
3799 minipage_open = false;
3802 os << "\\end{LyXParagraphIndent}\n";
3805 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3806 && par->pextra_hfill)) {
3810 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3811 return par; // ale970302
3815 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3816 ostream & foot, TexRow & foot_texrow,
3820 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3821 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3822 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3823 "No footnote!" << endl;
3825 LyXParagraph * par = this;
3826 LyXLayout const & style =
3827 textclasslist.Style(current_view->buffer()->params.textclass,
3828 previous->GetLayout());
3830 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3831 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3832 "Float other than footnote in command"
3833 " with moving argument is illegal" << endl;
3836 if (footnotekind != LyXParagraph::FOOTNOTE
3837 && footnotekind != LyXParagraph::MARGIN
3840 // How to solve this?
3841 //&& !suffixIs(file, '\n')
3843 // we need to ensure that real floats like tables and figures
3844 // have their \begin{} on a new line otherwise we can get
3845 // incorrect results when using the endfloat.sty package
3846 // especially if two floats follow one another. ARRae 981022
3847 // NOTE: if the file is length 0 it must have just been
3848 // written out so we assume it ended with a '\n'
3850 // As far as I can see there is never any harm in writing
3851 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3856 bool need_closing = false;
3857 bool is_rtl = isRightToLeftPar();
3858 if (is_rtl != parent_is_rtl) {
3863 need_closing = true;
3866 BufferParams * params = ¤t_view->buffer()->params;
3867 bool footer_in_body = true;
3868 switch (footnotekind) {
3869 case LyXParagraph::FOOTNOTE:
3870 if (style.intitle) {
3871 os << "\\thanks{\n";
3872 footer_in_body = false;
3874 if (foot_count == -1) {
3875 // we're at depth 0 so we can use:
3876 os << "\\footnote{%\n";
3877 footer_in_body = false;
3879 os << "\\footnotemark{}%\n";
3881 // we only need this when there are
3882 // multiple footnotes
3883 os << "\\stepcounter{footnote}";
3885 os << "\\footnotetext{%\n";
3886 foot_texrow.start(this, 0);
3887 foot_texrow.newline();
3892 case LyXParagraph::MARGIN:
3893 os << "\\marginpar{\n";
3895 case LyXParagraph::FIG:
3896 if (pextra_type == PEXTRA_FLOATFLT
3897 && (!pextra_width.empty()
3898 || !pextra_widthp.empty())) {
3899 if (!pextra_width.empty())
3900 os << "\\begin{floatingfigure}{"
3901 << pextra_width << "}\n";
3903 os << "\\begin{floatingfigure}{"
3904 << atoi(pextra_widthp.c_str())/100.0
3905 << "\\textwidth}\n";
3907 os << "\\begin{figure}";
3908 if (!params->float_placement.empty()) {
3909 os << '[' << params->float_placement << "]\n";
3915 case LyXParagraph::TAB:
3916 os << "\\begin{table}";
3917 if (!params->float_placement.empty()) {
3918 os << '[' << params->float_placement << "]\n";
3923 case LyXParagraph::WIDE_FIG:
3924 os << "\\begin{figure*}";
3925 if (!params->float_placement.empty()) {
3926 os << '[' << params->float_placement << "]\n";
3931 case LyXParagraph::WIDE_TAB:
3932 os << "\\begin{table*}";
3933 if (!params->float_placement.empty()) {
3934 os << '[' << params->float_placement << "]\n";
3939 case LyXParagraph::ALGORITHM:
3940 os << "\\begin{algorithm}\n";
3945 if (footnotekind != LyXParagraph::FOOTNOTE
3946 || !footer_in_body) {
3947 // Process text for all floats except footnotes in body
3949 LyXLayout const & style =
3951 .Style(current_view->buffer()->params
3955 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3957 if (style.isEnvironment()
3958 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3959 // Allows the use of minipages within float
3960 // environments. Shouldn't be circular because
3961 // we don't support footnotes inside
3962 // floats (yet). ARRae
3963 par = par->TeXEnvironment(os, texrow,
3967 par = par->TeXOnePar(os, texrow,
3972 if (par && !par->IsDummy() && par->depth > depth) {
3973 par = par->TeXDeeper(os, texrow,
3977 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3979 // process footnotes > depth 0 or in environments separately
3980 // NOTE: Currently don't support footnotes within footnotes
3981 // even though that is possible using the \footnotemark
3983 std::ostringstream dummy;
3987 TexRow dummy_texrow;
3988 int dummy_count = 0;
3990 LyXLayout const & style =
3992 .Style(current_view->buffer()->params
3996 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3998 if (style.isEnvironment()
3999 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4000 // Allows the use of minipages within float
4001 // environments. Shouldn't be circular because
4002 // we don't support footnotes inside
4003 // floats (yet). ARRae
4004 par = par->TeXEnvironment(foot, foot_texrow,
4005 dummy, dummy_texrow,
4008 par = par->TeXOnePar(foot, foot_texrow,
4009 dummy, dummy_texrow,
4013 if (par && !par->IsDummy() && par->depth > depth) {
4014 par = par->TeXDeeper(foot, foot_texrow,
4015 dummy, dummy_texrow,
4019 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4021 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4022 "Footnote in a Footnote -- not supported"
4025 #ifndef HAVE_OSTREAM
4026 delete [] dummy.str();
4030 switch (footnotekind) {
4031 case LyXParagraph::FOOTNOTE:
4032 if (footer_in_body) {
4033 // This helps tell which of the multiple
4034 // footnotetexts an error was in.
4036 foot_texrow.newline();
4041 case LyXParagraph::MARGIN:
4044 case LyXParagraph::FIG:
4045 if (pextra_type == PEXTRA_FLOATFLT
4046 && (!pextra_width.empty()
4047 || !pextra_widthp.empty()))
4048 os << "\\end{floatingfigure}";
4050 os << "\\end{figure}";
4052 case LyXParagraph::TAB:
4053 os << "\\end{table}";
4055 case LyXParagraph::WIDE_FIG:
4056 os << "\\end{figure*}";
4058 case LyXParagraph::WIDE_TAB:
4059 os << "\\end{table*}";
4061 case LyXParagraph::ALGORITHM:
4062 os << "\\end{algorithm}";
4069 if (footnotekind != LyXParagraph::FOOTNOTE
4070 && footnotekind != LyXParagraph::MARGIN) {
4071 // we need to ensure that real floats like tables and figures
4072 // have their \end{} on a line of their own otherwise we can
4073 // get incorrect results when using the endfloat.sty package.
4078 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4083 bool LyXParagraph::IsDummy() const
4085 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4086 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4090 void LyXParagraph::SetPExtraType(int type, char const * width,
4091 char const * widthp)
4094 pextra_width = width;
4095 pextra_widthp = widthp;
4097 if (textclasslist.Style(current_view->buffer()->params.textclass,
4098 layout).isEnvironment()) {
4103 while (par && (par->layout == layout)
4104 && (par->depth == depth)) {
4106 par = par->Previous();
4108 par = par->FirstPhysicalPar();
4109 while (par && par->depth > depth) {
4110 par = par->Previous();
4112 par = par->FirstPhysicalPar();
4116 while (par && (par->layout == layout)
4117 && (par->depth == depth)) {
4118 par->pextra_type = type;
4119 par->pextra_width = width;
4120 par->pextra_widthp = widthp;
4121 par = par->NextAfterFootnote();
4122 if (par && (par->depth > depth))
4123 par->SetPExtraType(type, width, widthp);
4124 while (par && ((par->depth > depth) || par->IsDummy()))
4125 par = par->NextAfterFootnote();
4131 void LyXParagraph::UnsetPExtraType()
4133 if (pextra_type == PEXTRA_NONE)
4136 pextra_type = PEXTRA_NONE;
4137 pextra_width.clear();
4138 pextra_widthp.clear();
4140 if (textclasslist.Style(current_view->buffer()->params.textclass,
4141 layout).isEnvironment()) {
4146 while (par && (par->layout == layout)
4147 && (par->depth == depth)) {
4149 par = par->Previous();
4151 par = par->FirstPhysicalPar();
4152 while (par && par->depth > depth) {
4153 par = par->Previous();
4155 par = par->FirstPhysicalPar();
4159 while (par && (par->layout == layout)
4160 && (par->depth == depth)) {
4161 par->pextra_type = PEXTRA_NONE;
4162 par->pextra_width.clear();
4163 par->pextra_widthp.clear();
4164 par = par->NextAfterFootnote();
4165 if (par && (par->depth > depth))
4166 par->UnsetPExtraType();
4167 while (par && ((par->depth > depth) || par->IsDummy()))
4168 par = par->NextAfterFootnote();
4174 bool LyXParagraph::IsHfill(size_type pos) const
4176 return IsHfillChar(GetChar(pos));
4180 bool LyXParagraph::IsInset(size_type pos) const
4182 return IsInsetChar(GetChar(pos));
4186 bool LyXParagraph::IsFloat(size_type pos) const
4188 return IsFloatChar(GetChar(pos));
4192 bool LyXParagraph::IsNewline(size_type pos) const
4194 return pos >= 0 && IsNewlineChar(GetChar(pos));
4198 bool LyXParagraph::IsSeparator(size_type pos) const
4200 return IsSeparatorChar(GetChar(pos));
4204 bool LyXParagraph::IsLineSeparator(size_type pos) const
4206 return IsLineSeparatorChar(GetChar(pos));
4210 bool LyXParagraph::IsKomma(size_type pos) const
4212 return IsKommaChar(GetChar(pos));
4216 /// Used by the spellchecker
4217 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4219 unsigned char c = GetChar(pos);
4220 if (IsLetterChar(c))
4222 // '\0' is not a letter, allthough every string contains "" (below)
4225 // We want to pass the ' and escape chars to ispell
4226 string extra = lyxrc.isp_esc_chars + '\'';
4230 return contains(extra, ch);
4234 bool LyXParagraph::IsWord(size_type pos ) const
4236 return IsWordChar(GetChar(pos)) ;
4240 Language const * LyXParagraph::getParLanguage() const
4244 return FirstPhysicalPar()->GetFirstFontSettings()
4247 for (size_type pos = 0; pos < size(); ++pos)
4249 return GetFontSettings(pos).language();
4250 return GetFirstFontSettings().language();
4253 return previous->getParLanguage();
4255 return current_view->buffer()->params.language_info;
4259 bool LyXParagraph::isRightToLeftPar() const
4261 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4265 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4267 for(size_type i = 0; i < size(); ++i) {
4268 LyXFont font = GetFontSettings(i);
4269 if (font.language() == from) {
4270 font.setLanguage(to);
4277 bool LyXParagraph::isMultiLingual()
4279 Language const * doc_language =
4280 current_view->buffer()->params.language_info;
4281 for(size_type i = 0; i < size(); ++i) {
4282 LyXFont font = GetFontSettings(i);
4283 if (font.language() != doc_language)