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;
44 int tex_code_break_column = 72; // needs non-zero initialization. set later.
45 // this is a bad idea, but how can LyXParagraph find its buffer to get
46 // parameters? (JMarc)
47 extern BufferView * current_view;
51 extern string bibitemWidthest(Painter &);
53 // this is a minibuffer
54 static char minibuffer_char;
55 static LyXFont minibuffer_font;
56 static Inset * minibuffer_inset;
59 // Initialization of the counter for the paragraph id's,
60 // declared in lyxparagraph.h
61 unsigned int LyXParagraph::paragraph_id = 0;
64 LyXParagraph::LyXParagraph()
66 text.reserve(500); // is this number too big?
68 for (int i = 0; i < 10; ++i) setCounter(i , 0);
74 footnoteflag = LyXParagraph::NO_FOOTNOTE;
75 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
77 align = LYX_ALIGN_BLOCK;
79 /* table stuff -- begin*/
81 /* table stuff -- end*/
84 bibkey = 0; // ale970302
89 // This konstruktor inserts the new paragraph in a list.
90 LyXParagraph::LyXParagraph(LyXParagraph * par)
93 par->text.resize(par->text.size());
95 for (int i = 0; i < 10; ++i) setCounter(i, 0);
99 // double linked list begin
102 next->previous = this;
104 previous->next = this;
106 footnoteflag = LyXParagraph::NO_FOOTNOTE;
107 footnotekind = LyXParagraph::FOOTNOTE;
109 /* table stuff -- begin*/
111 /* table stuff -- end*/
113 id_ = paragraph_id++;
115 bibkey = 0; // ale970302
121 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
122 char footflag, char dth) const
124 LyXFont font1, font2;
129 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
131 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
133 // The beginning or the end of a footnote environment?
134 if (footflag != footnoteflag) {
135 footflag = footnoteflag;
137 os << "\n\\begin_float "
138 << string_footnotekinds[footnotekind]
141 os << "\n\\end_float ";
145 // The beginning or end of a deeper (i.e. nested) area?
148 while (depth > dth) {
149 os << "\n\\begin_deeper ";
153 while (depth < dth) {
154 os << "\n\\end_deeper ";
160 // First write the layout
162 << textclasslist.NameOfLayout(params.textclass, layout)
165 // Maybe some vertical spaces.
166 if (added_space_top.kind() != VSpace::NONE)
167 os << "\\added_space_top "
168 << added_space_top.asLyXCommand() << " ";
169 if (added_space_bottom.kind() != VSpace::NONE)
170 os << "\\added_space_bottom "
171 << added_space_bottom.asLyXCommand() << " ";
173 // Maybe the paragraph has special spacing
174 spacing.writeFile(os, true);
176 // The labelwidth string used in lists.
177 if (!labelwidthstring.empty())
178 os << "\\labelwidthstring "
179 << labelwidthstring << '\n';
181 // Lines above or below?
185 os << "\\line_bottom ";
187 // Pagebreaks above or below?
189 os << "\\pagebreak_top ";
190 if (pagebreak_bottom)
191 os << "\\pagebreak_bottom ";
193 // Start of appendix?
194 if (start_of_appendix)
195 os << "\\start_of_appendix ";
202 if (align != LYX_ALIGN_LAYOUT) {
204 case LYX_ALIGN_LEFT: h = 1; break;
205 case LYX_ALIGN_RIGHT: h = 2; break;
206 case LYX_ALIGN_CENTER: h = 3; break;
207 default: h = 0; break;
209 os << "\\align " << string_align[h] << " ";
211 if (pextra_type != PEXTRA_NONE) {
212 os << "\\pextra_type " << pextra_type;
213 if (pextra_type == PEXTRA_MINIPAGE) {
214 os << " \\pextra_alignment "
217 os << " \\pextra_hfill "
219 if (pextra_start_minipage)
220 os << " \\pextra_start_minipage "
221 << pextra_start_minipage;
223 if (!pextra_width.empty()) {
224 os << " \\pextra_width "
225 << VSpace(pextra_width).asLyXCommand();
226 } else if (!pextra_widthp.empty()) {
227 os << " \\pextra_widthp "
233 // Dummy layout. This means that a footnote ended.
234 os << "\n\\end_float ";
235 footflag = LyXParagraph::NO_FOOTNOTE;
238 // It might be a table.
240 os << "\\LyXTable\n";
248 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
251 for (size_type i = 0; i < size(); ++i) {
257 // Write font changes
258 font2 = GetFontSettings(i);
259 if (font2 != font1) {
260 font2.lyxWriteChanges(font1, os);
269 Inset const * inset = GetInset(i);
271 if (inset->DirectWrite()) {
272 // international char, let it write
273 // code directly so it's shorter in
277 os << "\n\\begin_inset ";
279 os << "\n\\end_inset \n\n";
285 os << "\n\\newline \n";
289 os << "\n\\hfill \n";
293 os << "\n\\backslash \n";
297 if (i + 1 < size() && GetChar(i + 1) == ' ') {
304 if ((column > 70 && c == ' ')
309 // this check is to amend a bug. LyX sometimes
310 // inserts '\0' this could cause problems.
314 lyxerr << "ERROR (LyXParagraph::writeFile):"
315 " NULL char in structure." << endl;
321 // now write the next paragraph
323 next->writeFile(os, params, footflag, dth);
327 void LyXParagraph::validate(LaTeXFeatures & features) const
329 BufferParams const & params = features.bufferParams();
331 // this will be useful later
332 LyXLayout const & layout =
333 textclasslist.Style(params.textclass,
337 if (line_top || line_bottom)
338 features.lyxline = true;
339 if (!spacing.isDefault())
340 features.setspace = true;
343 features.layout[GetLayout()] = true;
346 Language const * doc_language = params.language_info;
348 for (FontList::const_iterator cit = fontlist.begin();
349 cit != fontlist.end(); ++cit) {
350 if ((*cit).font.noun() == LyXFont::ON) {
351 lyxerr[Debug::LATEX] << "font.noun: "
352 << (*cit).font.noun()
354 features.noun = true;
355 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
356 << (*cit).font.stateText()
359 switch ((*cit).font.color()) {
361 case LColor::inherit:
365 features.color = true;
366 lyxerr[Debug::LATEX] << "Color enabled. Font: "
367 << (*cit).font.stateText()
371 Language const * language = (*cit).font.language();
372 if (language != doc_language) {
373 features.UsedLanguages.insert(language);
374 lyxerr[Debug::LATEX] << "Found language "
375 << language->lang << endl;
380 // This is not efficient. I plan to use the code above, after I
381 // change the fontlist handling.
382 for (size_type i = 0; i < size(); ++i) {
383 Language const * language = GetFontSettings(i).language();
384 if (language != doc_language)
385 features.UsedLanguages.insert(language);
389 for (InsetList::const_iterator cit = insetlist.begin();
390 cit != insetlist.end(); ++cit) {
392 (*cit).inset->Validate(features);
395 if (table && table->IsLongTable())
396 features.longtable = true;
397 if (pextra_type == PEXTRA_INDENT)
398 features.LyXParagraphIndent = true;
399 if (pextra_type == PEXTRA_FLOATFLT)
400 features.floatflt = true;
401 if (layout.needprotect
402 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
403 features.NeedLyXFootnoteCode = true;
404 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
405 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
406 features.NeedLyXMinipageIndent = true;
407 if (table && table->NeedRotating())
408 features.rotating = true;
409 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
410 features.algorithm = true;
414 // First few functions needed for cut and paste and paragraph breaking.
415 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
417 minibuffer_char = GetChar(pos);
418 minibuffer_font = GetFontSettings(pos);
419 minibuffer_inset = 0;
420 if (minibuffer_char == LyXParagraph::META_INSET) {
422 minibuffer_inset = GetInset(pos)->Clone();
424 minibuffer_inset = 0;
425 minibuffer_char = ' ';
426 // This reflects what GetInset() does (ARRae)
432 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
434 minibuffer_char = GetChar(pos);
435 minibuffer_font = GetFontSettings(pos);
436 minibuffer_inset = 0;
437 if (minibuffer_char == LyXParagraph::META_INSET) {
439 minibuffer_inset = GetInset(pos);
440 // This is a little hack since I want exactly
441 // the inset, not just a clone. Otherwise
442 // the inset would be deleted when calling Erase(pos)
444 InsetList::iterator it = lower_bound(insetlist.begin(),
447 if (it != insetlist.end() && (*it).pos == pos)
450 minibuffer_inset = 0;
451 minibuffer_char = ' ';
452 // This reflects what GetInset() does (ARRae)
457 // Erase(pos); now the caller is responsible for that.
461 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
463 if ((minibuffer_char == LyXParagraph::META_INSET) &&
464 !InsertInsetAllowed(minibuffer_inset))
466 InsertChar(pos, minibuffer_char);
467 SetFont(pos, minibuffer_font);
468 if (minibuffer_char == LyXParagraph::META_INSET)
469 InsertInset(pos, minibuffer_inset);
477 void LyXParagraph::Clear()
482 pagebreak_top = false;
483 pagebreak_bottom = false;
485 added_space_top = VSpace(VSpace::NONE);
486 added_space_bottom = VSpace(VSpace::NONE);
487 spacing.set(Spacing::Default);
489 align = LYX_ALIGN_LAYOUT;
493 pextra_type = PEXTRA_NONE;
494 pextra_width.erase();
495 pextra_widthp.erase();
496 pextra_alignment = MINIPAGE_ALIGN_TOP;
497 pextra_hfill = false;
498 pextra_start_minipage = false;
501 labelwidthstring.erase();
505 start_of_appendix = false;
509 // the destructor removes the new paragraph from the list
510 LyXParagraph::~LyXParagraph()
513 previous->next = next;
515 next->previous = previous;
517 for (InsetList::iterator it = insetlist.begin();
518 it != insetlist.end(); ++it) {
522 /* table stuff -- begin*/
524 /* table stuff -- end*/
529 //lyxerr << "LyXParagraph::paragraph_id = "
530 // << LyXParagraph::paragraph_id << endl;
534 void LyXParagraph::Erase(LyXParagraph::size_type pos)
536 // > because last is the next unused position, and you can
537 // use it if you want
539 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
540 NextAfterFootnote()->Erase(pos - text.size() - 1);
542 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
543 "position does not exist." << endl;
546 if (pos < size()) { // last is free for insertation, but should be empty
547 // if it is an inset, delete the inset entry
548 if (text[pos] == LyXParagraph::META_INSET) {
550 InsetList::iterator it = lower_bound(insetlist.begin(),
553 if (it != insetlist.end() && (*it).pos == pos) {
558 text.erase(text.begin() + pos);
559 // Erase entries in the tables.
560 for (FontList::iterator it = fontlist.begin();
561 it != fontlist.end(); ++it) {
562 if (pos >= (*it).pos && pos <= (*it).pos_end) {
563 if ((*it).pos == (*it).pos_end) {
564 // If it is a multi-character font
565 // entry, we just make it smaller
566 // (see update below), otherwise we
573 // Update all other entries.
574 for (FontList::iterator it = fontlist.begin();
575 it != fontlist.end(); ++it) {
578 if ((*it).pos_end >= pos)
582 // Update the inset table.
583 for (InsetList::iterator it = upper_bound(insetlist.begin(),
586 it != insetlist.end(); ++it)
589 lyxerr << "ERROR (LyXParagraph::Erase): "
590 "can't erase non-existant char." << endl;
595 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
597 // > because last is the next unused position, and you can
598 // use it if you want
601 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
602 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
605 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
606 "position does not exist." << endl;
609 text.insert(text.begin() + pos, c);
610 // Update the font table.
611 for (FontList::iterator it = fontlist.begin();
612 it != fontlist.end(); ++it) {
613 if ((*it).pos >= pos)
615 if ((*it).pos_end >= pos)
619 // Update the inset table.
620 for (InsetList::iterator it = lower_bound(insetlist.begin(),
623 it != insetlist.end(); ++it)
628 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
631 // > because last is the next unused position, and you can
632 // use it if you want
635 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
637 ->InsertInset(pos - text.size() - 1, inset);
639 lyxerr << "ERROR (LyXParagraph::InsertInset): "
640 "position does not exist: " << pos << endl;
643 if (text[pos] != LyXParagraph::META_INSET) {
644 lyxerr << "ERROR (LyXParagraph::InsertInset): "
645 "there is no LyXParagraph::META_INSET" << endl;
650 // Add a new entry in the inset table.
651 InsetList::iterator it = lower_bound(insetlist.begin(),
654 if (it != insetlist.end() && (*it).pos == pos)
655 lyxerr << "ERROR (LyXParagraph::InsertInset): "
656 "there is an inset in position: " << pos << endl;
658 insetlist.insert(it, InsetTable(pos,inset));
660 inset->setOwner(inset_owner);
665 bool LyXParagraph::InsertInsetAllowed(Inset *inset)
668 printf("CODE:%d\n",inset->LyxCode());
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
1628 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1630 LyXParagraph * par = ParFromPos(pos);
1632 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1633 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1639 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1641 LyXParagraph * par = ParFromPos(pos);
1643 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1644 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1649 int LyXParagraph::GetEndLabel() const
1651 LyXParagraph const * par = this;
1652 int par_depth = GetDepth();
1654 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1656 textclasslist.Style(current_view->buffer()->params.textclass,
1657 layout).endlabeltype;
1658 if (endlabeltype != END_LABEL_NO_LABEL) {
1659 LyXParagraph const * last = this;
1660 if( footnoteflag == NO_FOOTNOTE)
1661 last = LastPhysicalPar();
1662 else if (next->footnoteflag == NO_FOOTNOTE)
1663 return endlabeltype;
1665 if (!last || !last->next)
1666 return endlabeltype;
1668 int next_depth = last->next->GetDepth();
1669 if (par_depth > next_depth ||
1670 (par_depth == next_depth && layout != last->next->GetLayout() ))
1671 return endlabeltype;
1676 par = par->DepthHook(par_depth - 1);
1678 par_depth = par->GetDepth();
1680 return END_LABEL_NO_LABEL;
1684 LyXTextClass::size_type LyXParagraph::GetLayout() const
1686 return FirstPhysicalPar()->layout;
1690 char LyXParagraph::GetDepth() const
1692 return FirstPhysicalPar()->depth;
1696 char LyXParagraph::GetAlign() const
1698 return FirstPhysicalPar()->align;
1702 string LyXParagraph::GetLabelstring() const
1704 return FirstPhysicalPar()->labelstring;
1708 int LyXParagraph::GetFirstCounter(int i) const
1710 return FirstPhysicalPar()->counter_[i];
1714 // the next two functions are for the manual labels
1715 string LyXParagraph::GetLabelWidthString() const
1717 if (!FirstPhysicalPar()->labelwidthstring.empty())
1718 return FirstPhysicalPar()->labelwidthstring;
1720 return _("Senseless with this layout!");
1724 void LyXParagraph::SetLabelWidthString(string const & s)
1726 LyXParagraph * par = FirstPhysicalPar();
1728 par->labelwidthstring = s;
1732 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1734 LyXParagraph * par = FirstPhysicalPar();
1735 LyXParagraph * ppar = 0;
1736 LyXParagraph * npar = 0;
1738 par->layout = new_layout;
1739 /* table stuff -- begin*/
1742 /* table stuff -- end*/
1743 if (par->pextra_type == PEXTRA_NONE) {
1744 if (par->Previous()) {
1745 ppar = par->Previous()->FirstPhysicalPar();
1748 && (ppar->depth > par->depth))
1749 ppar = ppar->Previous()->FirstPhysicalPar();
1752 npar = par->Next()->NextAfterFootnote();
1755 && (npar->depth > par->depth))
1756 npar = npar->Next()->NextAfterFootnote();
1758 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1760 p1 = ppar->pextra_width,
1761 p2 = ppar->pextra_widthp;
1762 ppar->SetPExtraType(ppar->pextra_type,
1763 p1.c_str(), p2.c_str());
1765 if ((par->pextra_type == PEXTRA_NONE) &&
1766 npar && (npar->pextra_type != PEXTRA_NONE)) {
1768 p1 = npar->pextra_width,
1769 p2 = npar->pextra_widthp;
1770 npar->SetPExtraType(npar->pextra_type,
1771 p1.c_str(), p2.c_str());
1777 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1780 * par = FirstPhysicalPar(),
1784 par->layout = new_layout;
1785 par->labelwidthstring.erase();
1786 par->align = LYX_ALIGN_LAYOUT;
1787 par->added_space_top = VSpace(VSpace::NONE);
1788 par->added_space_bottom = VSpace(VSpace::NONE);
1789 par->spacing.set(Spacing::Default);
1791 /* table stuff -- begin*/
1794 /* table stuff -- end*/
1795 if (par->pextra_type == PEXTRA_NONE) {
1796 if (par->Previous()) {
1797 ppar = par->Previous()->FirstPhysicalPar();
1800 && (ppar->depth > par->depth))
1801 ppar = ppar->Previous()->FirstPhysicalPar();
1804 npar = par->Next()->NextAfterFootnote();
1807 && (npar->depth > par->depth))
1808 npar = npar->Next()->NextAfterFootnote();
1810 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1812 p1 = ppar->pextra_width,
1813 p2 = ppar->pextra_widthp;
1814 ppar->SetPExtraType(ppar->pextra_type,
1815 p1.c_str(), p2.c_str());
1817 if ((par->pextra_type == PEXTRA_NONE) &&
1818 npar && (npar->pextra_type != PEXTRA_NONE)) {
1820 p1 = npar->pextra_width,
1821 p2 = npar->pextra_widthp;
1822 npar->SetPExtraType(npar->pextra_type,
1823 p1.c_str(), p2.c_str());
1829 // if the layout of a paragraph contains a manual label, the beginning of the
1830 // main body is the beginning of the second word. This is what the par-
1831 // function returns. If the layout does not contain a label, the main
1832 // body always starts with position 0. This differentiation is necessary,
1833 // because there cannot be a newline or a blank <= the beginning of the
1834 // main body in TeX.
1836 int LyXParagraph::BeginningOfMainBody() const
1838 if (FirstPhysicalPar() != this)
1841 // Unroll the first two cycles of the loop
1842 // and remember the previous character to
1843 // remove unnecessary GetChar() calls
1846 && GetChar(i) != LyXParagraph::META_NEWLINE
1849 char previous_char = 0, temp = 0;
1851 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1852 // Yes, this ^ is supposed to be "= " not "=="
1855 && previous_char != ' '
1856 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1858 previous_char = temp;
1863 if (i == 0 && i == size() &&
1864 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1865 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1866 ++i; /* the cursor should not jump
1867 * to the main body if there
1873 LyXParagraph * LyXParagraph::DepthHook(int deth)
1875 LyXParagraph * newpar = this;
1880 newpar = newpar->FirstPhysicalPar()->Previous();
1881 } while (newpar && newpar->GetDepth() > deth
1882 && newpar->footnoteflag == footnoteflag);
1885 if (Previous() || GetDepth())
1886 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1890 return newpar->FirstPhysicalPar();
1894 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1896 LyXParagraph const * newpar = this;
1901 newpar = newpar->FirstPhysicalPar()->Previous();
1902 } while (newpar && newpar->GetDepth() > deth
1903 && newpar->footnoteflag == footnoteflag);
1906 if (Previous() || GetDepth())
1907 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1911 return newpar->FirstPhysicalPar();
1915 int LyXParagraph::AutoDeleteInsets()
1918 InsetList::size_type index = 0;
1919 while (index < insetlist.size()) {
1920 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1921 Erase(insetlist[index].pos);
1922 // Erase() calls to insetlist.erase(&insetlist[index])
1923 // so index shouldn't be increased.
1932 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1934 InsetList::iterator it = lower_bound(insetlist.begin(),
1937 if (it != insetlist.end()) {
1945 // returns -1 if inset not found
1946 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1949 // We could use lower_bound here too, we just need to add
1950 // the approp. operator() to matchIT (and change the name
1951 // of that struct). Code would then be:
1952 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1954 // inset, matchIT());
1955 // if ((*cit).inset == inset) {
1956 // return (*cit).pos;
1958 for (InsetList::const_iterator cit = insetlist.begin();
1959 cit != insetlist.end(); ++cit) {
1960 if ((*cit).inset == inset) {
1964 // Think about footnotes.
1965 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1966 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1968 NextAfterFootnote()->GetPositionOfInset(inset);
1970 return text.size() + 1 + further;
1976 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1979 TexRow & foot_texrow,
1982 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1983 LyXLayout const & style =
1984 textclasslist.Style(current_view->buffer()->params.textclass,
1987 bool further_blank_line = false;
1989 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1991 if (start_of_appendix) {
1992 os << "\\appendix\n";
1996 if (!spacing.isDefault()
1997 && (!Previous() || !Previous()->HasSameLayout(this))) {
1998 os << spacing.writeEnvirBegin() << "\n";
2002 if (tex_code_break_column && style.isCommand()){
2007 if (pagebreak_top) {
2009 further_blank_line = true;
2011 if (added_space_top.kind() != VSpace::NONE) {
2012 os << added_space_top.asLatexCommand(current_view->buffer()->params);
2013 further_blank_line = true;
2017 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2018 << "\\vspace{-1\\parskip}";
2019 further_blank_line = true;
2022 if (further_blank_line){
2027 Language const * language = getParLanguage();
2028 Language const * doc_language = current_view->buffer()->params.language_info;
2029 if (language != doc_language) {
2030 os << subst(lyxrc.language_command_begin, "$$lang",
2036 switch (style.latextype) {
2039 << style.latexname()
2040 << style.latexparam();
2042 case LATEX_ITEM_ENVIRONMENT:
2044 bibkey->Latex(os, false, false);
2048 case LATEX_LIST_ENVIRONMENT:
2055 bool need_par = SimpleTeXOnePar(os, texrow, moving_arg);
2057 // Spit out footnotes
2058 LyXParagraph * par = next;
2059 if (lyxrc.rtl_support) {
2060 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2061 && next->footnoteflag != footnoteflag) {
2062 LyXParagraph * p = 0;
2063 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2064 if ( (p = NextAfterFootnote()) != 0 &&
2065 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2066 is_rtl = GetFontSettings(0).isRightToLeft();
2068 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2069 par->footnoteflag != footnoteflag) {
2070 par = par->TeXFootnote(os, texrow, foot,
2071 foot_texrow, foot_count,
2073 par->SimpleTeXOnePar(os, texrow, moving_arg);
2074 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2076 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2077 (p = par->NextAfterFootnote()) != 0 &&
2078 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2079 is_rtl = GetFontSettings(0).isRightToLeft();
2084 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2085 && par->footnoteflag != footnoteflag) {
2086 par = par->TeXFootnote(os, texrow,
2087 foot, foot_texrow, foot_count,
2089 par->SimpleTeXOnePar(os, texrow, moving_arg);
2094 // Make sure that \\par is done with the font of the last
2095 // character if this has another size as the default.
2096 // This is necessary because LaTeX (and LyX on the screen)
2097 // calculates the space between the baselines according
2098 // to this font. (Matthias)
2099 LyXFont font = getFont(Last() - 1);
2101 if (style.resfont.size() != font.size()) {
2107 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2108 GetLayout()).isCommand()){
2109 if (style.resfont.size() != font.size()) {
2115 } else if (style.resfont.size() != font.size()){
2116 os << "{\\" << font.latexSize() << " \\par}";
2119 if (language != doc_language) {
2121 << subst(lyxrc.language_command_end, "$$lang",
2122 doc_language->lang);
2125 switch (style.latextype) {
2126 case LATEX_ITEM_ENVIRONMENT:
2127 case LATEX_LIST_ENVIRONMENT:
2128 if (par && (depth < par->depth)) {
2133 case LATEX_ENVIRONMENT:
2134 // if its the last paragraph of the current environment
2135 // skip it otherwise fall through
2137 && (par->layout != layout
2138 || par->depth != depth
2139 || par->pextra_type != pextra_type))
2142 // we don't need it for the last paragraph!!!
2143 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2144 && footnotekind != LyXParagraph::FOOTNOTE
2145 && footnotekind != LyXParagraph::MARGIN
2149 // don't insert this if we would be adding it
2150 // before or after a table in a float. This
2151 // little trick is needed in order to allow
2152 // use of tables in \subfigures or \subtables.
2158 further_blank_line = false;
2160 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2161 further_blank_line = true;
2164 if (added_space_bottom.kind() != VSpace::NONE) {
2165 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2166 further_blank_line = true;
2169 if (pagebreak_bottom) {
2171 further_blank_line = true;
2174 if (further_blank_line){
2179 if (!spacing.isDefault()
2180 && (!par || !par->HasSameLayout(this))) {
2181 os << spacing.writeEnvirEnd() << "\n";
2185 // we don't need it for the last paragraph!!!
2186 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2187 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2192 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2197 // This one spits out the text of the paragraph
2198 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow,
2201 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2204 return SimpleTeXOneTablePar(os, texrow);
2206 bool return_value = false;
2208 LyXLayout const & style =
2209 textclasslist.Style(current_view->buffer()->params.textclass,
2211 LyXFont basefont, last_font;
2213 // Maybe we have to create a optional argument.
2214 size_type main_body;
2215 if (style.labeltype != LABEL_MANUAL)
2218 main_body = BeginningOfMainBody();
2220 if (main_body > 0) {
2222 basefont = getFont(-2); // Get label font
2224 basefont = getFont(-1); // Get layout font
2232 if (style.isCommand()) {
2235 } else if (align != LYX_ALIGN_LAYOUT) {
2238 return_value = true;
2242 moving_arg |= style.needprotect;
2244 // Which font is currently active?
2245 LyXFont running_font(basefont);
2246 // Do we have an open font change?
2247 bool open_font = false;
2249 texrow.start(this, 0);
2251 for (size_type i = 0; i < size(); ++i) {
2253 // First char in paragraph or after label?
2254 if (i == main_body && !IsDummy()) {
2255 if (main_body > 0) {
2257 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2260 basefont = getFont(-1); // Now use the layout font
2261 running_font = basefont;
2265 if (style.isCommand()) {
2268 } else if (align != LYX_ALIGN_LAYOUT) {
2271 return_value = true;
2275 os << "\\noindent ";
2279 case LYX_ALIGN_NONE:
2280 case LYX_ALIGN_BLOCK:
2281 case LYX_ALIGN_LAYOUT:
2282 case LYX_ALIGN_SPECIAL:
2284 case LYX_ALIGN_LEFT:
2285 if (getParLanguage()->lang != "hebrew") {
2286 os << "\\raggedright ";
2289 os << "\\raggedleft ";
2293 case LYX_ALIGN_RIGHT:
2294 if (getParLanguage()->lang != "hebrew") {
2295 os << "\\raggedleft ";
2298 os << "\\raggedright ";
2302 case LYX_ALIGN_CENTER:
2303 os << "\\centering ";
2311 // Fully instantiated font
2312 LyXFont font = getFont(i);
2313 LyXParagraph * p = 0;
2314 if (i == 0 && previous &&
2315 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2316 (p = PreviousBeforeFootnote()) != 0)
2317 last_font = p->getFont(p->size()-1);
2319 last_font = running_font;
2321 // Spaces at end of font change are simulated to be
2322 // outside font change, i.e. we write "\textXX{text} "
2323 // rather than "\textXX{text }". (Asger)
2324 if (open_font && c == ' ' && i <= size() - 2
2325 && !getFont(i+1).equalExceptLatex(running_font)
2326 && !getFont(i+1).equalExceptLatex(font)) {
2327 font = getFont(i + 1);
2329 // We end font definition before blanks
2330 if (!font.equalExceptLatex(running_font) && open_font) {
2331 column += running_font.latexWriteEndChanges(os,
2333 (i == main_body-1) ? basefont : font);
2334 running_font = basefont;
2338 // Blanks are printed before start of fontswitch
2340 // Do not print the separation of the optional argument
2341 if (i != main_body - 1) {
2342 SimpleTeXBlanks(os, texrow, i,
2343 column, font, style);
2347 // Do we need to change font?
2348 if (!font.equalExceptLatex(running_font)
2349 && i != main_body-1) {
2350 column += font.latexWriteStartChanges(os, basefont,
2352 running_font = font;
2356 if (c == LyXParagraph::META_NEWLINE) {
2357 // newlines are handled differently here than
2358 // the default in SimpleTeXSpecialChars().
2359 if (!style.newline_allowed
2360 || font.latex() == LyXFont::ON) {
2364 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2367 basefont = getFont(-1);
2368 running_font = basefont;
2369 if (font.family() ==
2370 LyXFont::TYPEWRITER_FAMILY) {
2378 texrow.start(this, i + 1);
2381 SimpleTeXSpecialChars(os, texrow, moving_arg,
2382 font, running_font, basefont,
2383 open_font, style, i, column, c);
2387 // If we have an open font definition, we have to close it
2389 LyXParagraph * p = 0;
2390 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2391 && (p = NextAfterFootnote()) != 0)
2392 running_font.latexWriteEndChanges(os, basefont,
2395 running_font.latexWriteEndChanges(os, basefont, basefont);
2398 // Needed if there is an optional argument but no contents.
2399 if (main_body > 0 && main_body == size()) {
2401 return_value = false;
2404 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2405 return return_value;
2409 // This one spits out the text of a table paragraph
2410 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2412 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2414 bool return_value = false;
2416 LyXLayout const & style =
2417 textclasslist.Style(current_view->buffer()->params.textclass,
2421 if (!IsDummy()) { // it is dummy if it is in a float!!!
2422 if (style.isCommand()) {
2425 } else if (align != LYX_ALIGN_LAYOUT) {
2428 return_value = true;
2431 os << "\\noindent ";
2435 case LYX_ALIGN_NONE:
2436 case LYX_ALIGN_BLOCK:
2437 case LYX_ALIGN_LAYOUT:
2438 case LYX_ALIGN_SPECIAL: break;
2439 case LYX_ALIGN_LEFT:
2440 os << "\\raggedright ";
2443 case LYX_ALIGN_RIGHT:
2444 os << "\\raggedleft ";
2447 case LYX_ALIGN_CENTER:
2448 os << "\\centering ";
2454 LyXFont basefont = getFont(-1); // Get layout font
2455 // Which font is currently active?
2456 LyXFont running_font = basefont;
2458 // Do we have an open font change?
2459 bool open_font = false;
2460 int current_cell_number = -1;
2461 int tmp = table->TexEndOfCell(os, current_cell_number);
2462 for (; tmp > 0 ; --tmp)
2465 texrow.start(this, 0);
2467 bool is_rtl = getParLanguage()->RightToLeft;
2468 bool first_in_cell = true;
2470 for (size_type i = 0; i < size(); ++i) {
2471 char c = GetChar(i);
2472 if (table->IsContRow(current_cell_number + 1)) {
2473 if (c == LyXParagraph::META_NEWLINE)
2474 ++current_cell_number;
2479 if (first_in_cell && is_rtl) {
2482 first_in_cell = false;
2485 // Fully instantiated font
2486 LyXFont font = getFont(i);
2487 last_font = running_font;
2489 // Spaces at end of font change are simulated to be
2490 // outside font change.
2491 // i.e. we write "\textXX{text} " rather than
2492 // "\textXX{text }". (Asger)
2493 if (open_font && c == ' ' && i <= size() - 2
2494 && getFont(i + 1) != running_font
2495 && getFont(i + 1) != font) {
2496 font = getFont(i + 1);
2499 // We end font definition before blanks
2500 if (font != running_font && open_font) {
2501 column += running_font.latexWriteEndChanges(os,
2504 running_font = basefont;
2507 // Blanks are printed before start of fontswitch
2509 SimpleTeXBlanks(os, texrow, i, column, font, style);
2511 // Do we need to change font?
2512 if (font != running_font) {
2513 column += font.latexWriteStartChanges(os, basefont,
2515 running_font = font;
2518 // Do we need to turn on LaTeX mode?
2519 if (font.latex() != running_font.latex()) {
2520 if (font.latex() == LyXFont::ON
2521 && style.needprotect) {
2526 if (c == LyXParagraph::META_NEWLINE) {
2527 // special case for inside a table
2528 // different from default case in
2529 // SimpleTeXSpecialChars()
2531 column += running_font
2532 .latexWriteEndChanges(os, basefont,
2536 basefont = getFont(-1);
2537 running_font = basefont;
2538 ++current_cell_number;
2539 if (table->CellHasContRow(current_cell_number) >= 0) {
2540 TeXContTableRows(os, i + 1,
2541 current_cell_number,
2544 if (is_rtl && !first_in_cell) {
2546 first_in_cell = true;
2549 // if this cell follow only ContRows till end don't
2550 // put the EndOfCell because it is put after the
2552 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2553 --current_cell_number;
2556 int tmp = table->TexEndOfCell(os,
2557 current_cell_number);
2560 } else if (tmp < 0) {
2566 texrow.start(this, i + 1);
2568 SimpleTeXSpecialChars(os, texrow, false,
2569 font, running_font, basefont,
2570 open_font, style, i, column, c);
2574 // If we have an open font definition, we have to close it
2576 running_font.latexWriteEndChanges(os, basefont, basefont);
2578 ++current_cell_number;
2579 if (is_rtl && !first_in_cell)
2581 tmp = table->TexEndOfCell(os, current_cell_number);
2582 for (; tmp > 0; --tmp)
2584 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2585 return return_value;
2589 // This one spits out the text off ContRows in tables
2590 bool LyXParagraph::TeXContTableRows(ostream & os,
2591 LyXParagraph::size_type i,
2592 int current_cell_number,
2593 int & column, TexRow & texrow)
2595 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2601 bool return_value = false;
2602 LyXLayout const & style =
2603 textclasslist.Style(current_view->buffer()->params.textclass,
2605 LyXFont basefont = getFont(-1); // Get layout font
2607 // Which font is currently active?
2608 LyXFont running_font = basefont;
2609 // Do we have an open font change?
2610 bool open_font = false;
2612 size_type lastpos = i;
2613 int cell = table->CellHasContRow(current_cell_number);
2614 ++current_cell_number;
2616 // first find the right position
2618 for (; (i < size()) && (current_cell_number<cell); ++i) {
2620 if (c == LyXParagraph::META_NEWLINE)
2621 ++current_cell_number;
2625 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2629 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2634 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2638 // Fully instantiated font
2639 LyXFont font = getFont(i);
2640 last_font = running_font;
2642 // Spaces at end of font change are simulated to
2643 // be outside font change. i.e. we write
2644 // "\textXX{text} " rather than "\textXX{text }".
2646 if (open_font && c == ' ' && i <= size() - 2
2647 && getFont(i + 1) != running_font
2648 && getFont(i + 1) != font) {
2649 font = getFont(i + 1);
2652 // We end font definition before blanks
2653 if (font != running_font && open_font) {
2654 column += running_font.latexWriteEndChanges(os, basefont, font);
2655 running_font = basefont;
2658 // Blanks are printed before start of fontswitch
2660 SimpleTeXBlanks(os, texrow, i,
2661 column, font, style);
2663 // Do we need to change font?
2664 if (font != running_font) {
2666 font.latexWriteStartChanges(os,
2669 running_font = font;
2672 // Do we need to turn on LaTeX mode?
2673 if (font.latex() != running_font.latex()) {
2674 if (font.latex() == LyXFont::ON
2675 && style.needprotect) {
2680 SimpleTeXSpecialChars(os, texrow, false, font,
2681 running_font, basefont,
2682 open_font, style, i, column, c);
2684 // If we have an open font definition, we have to close it
2686 running_font.latexWriteEndChanges(os, basefont,
2690 basefont = getFont(-1);
2691 running_font = basefont;
2692 cell = table->CellHasContRow(current_cell_number);
2694 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2695 return return_value;
2699 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2701 bool retval = false;
2703 case LyXParagraph::META_HFILL:
2704 sgml_string.erase();
2706 case LyXParagraph::META_NEWLINE:
2710 sgml_string = "&";
2713 sgml_string = "<";
2716 sgml_string = ">";
2719 sgml_string = "$";
2722 sgml_string = "#";
2725 sgml_string = "%";
2728 sgml_string = "[";
2731 sgml_string = "]";
2734 sgml_string = "{";
2737 sgml_string = "}";
2740 sgml_string = "˜";
2743 sgml_string = """;
2746 sgml_string = "\";
2752 case '\0': // Ignore :-)
2753 sgml_string.erase();
2763 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2764 int & desc_on, int depth)
2767 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2769 LyXFont font1, font2;
2772 size_type main_body;
2773 bool emph_flag = false;
2775 LyXLayout const & style =
2776 textclasslist.Style(current_view->buffer()->params.textclass,
2779 if (style.labeltype != LABEL_MANUAL)
2782 main_body = BeginningOfMainBody();
2784 // Gets paragraph main font.
2786 font1 = style.labelfont;
2790 int char_line_count = depth;
2791 os << newlineAndDepth(depth);
2792 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2793 os << "<INFORMALTABLE>"
2794 << newlineAndDepth(++depth);
2796 int current_cell_number = -1;
2797 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2799 // Parsing main loop.
2800 for (size_type i = 0; i < size(); ++i) {
2802 if (table->IsContRow(current_cell_number+1)) {
2803 if (c == LyXParagraph::META_NEWLINE)
2804 ++current_cell_number;
2809 // Fully instantiated font
2812 // Handle <emphasis> tag.
2813 if (font1.emph() != font2.emph() && i) {
2814 if (font2.emph() == LyXFont::ON) {
2817 } else if (emph_flag) {
2818 os << "</emphasis>";
2822 if (c == LyXParagraph::META_NEWLINE) {
2823 // We have only to control for emphasis open here!
2825 os << "</emphasis>";
2828 font1 = font2 = getFont(-1);
2829 ++current_cell_number;
2830 if (table->CellHasContRow(current_cell_number) >= 0) {
2831 DocBookContTableRows(os, extra, desc_on, i + 1,
2832 current_cell_number,
2835 // if this cell follow only ContRows till end don't
2836 // put the EndOfCell because it is put after the
2838 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2839 --current_cell_number;
2842 tmp = table->DocBookEndOfCell(os,
2843 current_cell_number,
2848 } else if (c == LyXParagraph::META_INSET) {
2849 inset = GetInset(i);
2851 std::ostringstream ost;
2852 inset->DocBook(ost);
2853 string tmp_out = ost.str().c_str();
2856 inset->DocBook(ost);
2858 char * ctmp = ost.str();
2859 string tmp_out(ctmp);
2863 // This code needs some explanation:
2864 // Two insets are treated specially
2865 // label if it is the first element in a
2866 // command paragraph
2868 // graphics inside tables or figure floats
2870 // title (the equivalente in latex for this
2872 // and title should come first
2875 if(desc_on != 3 || i != 0) {
2876 if(tmp_out[0] == '@') {
2878 extra += frontStrip(tmp_out,
2881 os << frontStrip(tmp_out,
2886 } else if (font2.latex() == LyXFont::ON) {
2887 // "TeX"-Mode on == > SGML-Mode on.
2893 if (linuxDocConvertChar(c, sgml_string)
2894 && !style.free_spacing) {
2895 // in freespacing mode, spaces are
2896 // non-breaking characters
2901 << "</term><listitem><para>";
2913 // Needed if there is an optional argument but no contents.
2914 if (main_body > 0 && main_body == size()) {
2919 os << "</emphasis>";
2922 ++current_cell_number;
2923 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2924 // Resets description flag correctly.
2927 // <term> not closed...
2931 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2932 os << "</INFORMALTABLE>";
2934 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2939 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2941 LyXParagraph::size_type i,
2942 int current_cell_number, int &column)
2947 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2952 //string emph = "emphasis";
2953 bool emph_flag = false;
2954 int char_line_count = 0;
2956 LyXLayout const & style =
2957 textclasslist.Style(current_view->buffer()->params.textclass,
2960 size_type main_body;
2961 if (style.labeltype != LABEL_MANUAL)
2964 main_body = BeginningOfMainBody();
2966 // Gets paragraph main font.
2969 font1 = style.labelfont;
2973 size_type lastpos = i;
2974 int cell = table->CellHasContRow(current_cell_number);
2975 ++current_cell_number;
2977 // first find the right position
2979 for (; i < size() && current_cell_number < cell; ++i) {
2981 if (c == LyXParagraph::META_NEWLINE)
2982 ++current_cell_number;
2986 // I don't know how to handle this so I comment it
2987 // for the moment (Jug)
2988 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2989 // file += " \\\\\n";
2992 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2997 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3001 // Fully instantiated font
3004 // Handle <emphasis> tag.
3005 if (font1.emph() != font2.emph() && i) {
3006 if (font2.emph() == LyXFont::ON) {
3009 } else if (emph_flag) {
3010 os << "</emphasis>";
3014 if (c == LyXParagraph::META_INSET) {
3015 inset = GetInset(i);
3017 std::ostringstream ost;
3018 inset->DocBook(ost);
3019 string tmp_out = ost.str().c_str();
3022 inset->DocBook(ost);
3024 char * ctmp = ost.str();
3025 string tmp_out(ctmp);
3029 // This code needs some explanation:
3030 // Two insets are treated specially
3031 // label if it is the first element in a
3032 // command paragraph
3034 // graphics inside tables or figure floats
3035 // can't go on title (the equivalente in
3036 // latex for this case is caption and title
3037 // should come first
3040 if(desc_on != 3 || i != 0) {
3041 if(tmp_out[0] == '@') {
3043 extra += frontStrip(tmp_out, '@');
3045 os << frontStrip(tmp_out, '@');
3049 } else if (font2.latex() == LyXFont::ON) {
3050 // "TeX"-Mode on == > SGML-Mode on.
3056 if (linuxDocConvertChar(c, sgml_string)
3057 && !style.free_spacing) {
3058 // in freespacing mode, spaces are
3059 // non-breaking characters
3064 << "</term><listitem><para>";
3074 // we have only to control for emphasis open here!
3076 os << "</emphasis>";
3079 font1 = font2 = getFont(-1);
3080 cell = table->CellHasContRow(current_cell_number);
3082 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3086 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3087 LyXParagraph::size_type const i,
3088 int & column, LyXFont const & font,
3089 LyXLayout const & style)
3091 if (column > tex_code_break_column
3093 && GetChar(i - 1) != ' '
3095 // In LaTeX mode, we don't want to
3096 // break lines since some commands
3098 && ! (font.latex() == LyXFont::ON)
3099 // same in FreeSpacing mode
3100 && !style.free_spacing
3101 // In typewriter mode, we want to avoid
3102 // ! . ? : at the end of a line
3103 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3104 && (GetChar(i-1) == '.'
3105 || GetChar(i-1) == '?'
3106 || GetChar(i-1) == ':'
3107 || GetChar(i-1) == '!'))) {
3108 if (tex_code_break_column == 0) {
3109 // in batchmode we need LaTeX to still
3110 // see it as a space not as an extra '\n'
3116 texrow.start(this, i + 1);
3118 } else if (font.latex() == LyXFont::OFF) {
3119 if (style.free_spacing) {
3128 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3131 LyXFont & running_font,
3134 LyXLayout const & style,
3135 LyXParagraph::size_type & i,
3136 int & column, char const c)
3138 // Two major modes: LaTeX or plain
3139 // Handle here those cases common to both modes
3140 // and then split to handle the two modes separately.
3142 case LyXParagraph::META_INSET: {
3143 Inset * inset = GetInset(i);
3146 int len = os.tellp();
3147 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3148 || inset->LyxCode() == Inset::MATH_CODE
3149 || inset->LyxCode() == Inset::URL_CODE)
3150 && running_font.isRightToLeft()) {
3155 int tmp = inset->Latex(os, moving_arg,
3156 style.free_spacing);
3164 column += os.tellp() - len;
3173 case LyXParagraph::META_NEWLINE:
3175 column += running_font.latexWriteEndChanges(os,
3180 basefont = getFont(-1);
3181 running_font = basefont;
3184 case LyXParagraph::META_HFILL:
3190 // And now for the special cases within each mode
3191 // Are we in LaTeX mode?
3192 if (font.latex() == LyXFont::ON) {
3193 // at present we only have one option
3194 // but I'll leave it as a switch statement
3195 // so its simpler to extend. (ARRae)
3198 // make sure that we will not print
3199 // error generating chars to the tex
3200 // file. This test would not be needed
3201 // if it were done in the buffer
3209 // Plain mode (i.e. not LaTeX)
3212 os << "\\textbackslash{}";
3216 case '°': case '±': case '²': case '³':
3217 case '×': case '÷': case '¹': case 'ª':
3218 case 'º': case '¬': case 'µ':
3219 if (current_view->buffer()->params.inputenc == "latin1") {
3220 os << "\\ensuremath{"
3229 case '|': case '<': case '>':
3230 // In T1 encoding, these characters exist
3231 if (lyxrc.fontenc == "T1") {
3233 //... but we should avoid ligatures
3234 if ((c == '>' || c == '<')
3236 && GetChar(i + 1) == c){
3237 os << "\\textcompwordmark{}";
3242 // Typewriter font also has them
3243 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3247 // Otherwise, we use what LaTeX
3251 os << "\\textless{}";
3255 os << "\\textgreater{}";
3259 os << "\\textbar{}";
3265 case '-': // "--" in Typewriter mode -> "-{}-"
3267 && GetChar(i + 1) == '-'
3268 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3277 os << "\\char`\\\"{}";
3282 if (current_view->buffer()->params.inputenc == "default") {
3291 case '%': case '#': case '{':
3298 os << "\\textasciitilde{}";
3303 os << "\\textasciicircum{}";
3307 case '*': case '[': case ']':
3308 // avoid being mistaken for optional arguments
3309 os << '{' << c << '}';
3314 // Blanks are printed before font switching.
3315 // Sure? I am not! (try nice-latex)
3316 // I am sure it's correct. LyX might be smarter
3317 // in the future, but for now, nothing wrong is
3322 /* idea for labels --- begin*/
3326 && font.family() != LyXFont::TYPEWRITER_FAMILY
3327 && GetChar(i + 1) == 'y'
3328 && GetChar(i + 2) == 'X') {
3336 && font.family() != LyXFont::TYPEWRITER_FAMILY
3337 && GetChar(i + 1) == 'e'
3338 && GetChar(i + 2) == 'X') {
3343 // Check for "LaTeX2e"
3346 && font.family() != LyXFont::TYPEWRITER_FAMILY
3347 && GetChar(i + 1) == 'a'
3348 && GetChar(i + 2) == 'T'
3349 && GetChar(i + 3) == 'e'
3350 && GetChar(i + 4) == 'X'
3351 && GetChar(i + 5) == '2'
3352 && GetChar(i + 6) == 'e') {
3357 // Check for "LaTeX"
3360 && font.family() != LyXFont::TYPEWRITER_FAMILY
3361 && GetChar(i + 1) == 'a'
3362 && GetChar(i + 2) == 'T'
3363 && GetChar(i + 3) == 'e'
3364 && GetChar(i + 4) == 'X') {
3368 /* idea for labels --- end*/
3369 } else if (c != '\0') {
3380 bool LyXParagraph::RoffContTableRows(ostream & os,
3381 LyXParagraph::size_type i,
3387 LyXFont font1(LyXFont::ALL_INHERIT);
3392 string fname2 = TmpFileName(string(), "RAT2");
3394 int cell = table->CellHasContRow(actcell);
3397 // first find the right position
3399 for (; i < size() && actcell < cell; ++i) {
3401 if (c == LyXParagraph::META_NEWLINE)
3406 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3409 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3411 font2 = GetFontSettings(i);
3412 if (font1.latex() != font2.latex()) {
3413 if (font2.latex() != LyXFont::OFF)
3418 case LyXParagraph::META_INSET:
3419 if ((inset = GetInset(i))) {
3421 stringstream ss(ios::in | ios::out);
3448 case LyXParagraph::META_NEWLINE:
3450 case LyXParagraph::META_HFILL:
3459 lyxerr.debug() << "RoffAsciiTable: "
3460 "NULL char in structure."
3465 cell = table->CellHasContRow(actcell);
3472 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3474 TexRow & foot_texrow,
3477 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3478 LyXParagraph * par = this;
3481 (par->depth == depth) &&
3482 (par->footnoteflag == footnoteflag)) {
3484 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3485 if (textclasslist.Style(current_view->buffer()->params.textclass,
3486 par->layout).isEnvironment()
3487 || par->pextra_type != PEXTRA_NONE) {
3488 par = par->TeXEnvironment(os, texrow,
3492 par = par->TeXOnePar(os, texrow, false,
3497 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3503 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3505 TexRow & foot_texrow,
3508 bool eindent_open = false;
3509 bool foot_this_level = false;
3510 // flags when footnotetext should be appended to file.
3511 static bool minipage_open = false;
3512 static int minipage_open_depth = 0;
3513 char par_sep = current_view->buffer()->params.paragraph_separation;
3515 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3517 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3519 LyXLayout const & style =
3520 textclasslist.Style(current_view->buffer()->params.textclass,
3523 if (pextra_type == PEXTRA_INDENT) {
3524 if (!pextra_width.empty()) {
3525 os << "\\begin{LyXParagraphIndent}{"
3526 << pextra_width << "}\n";
3528 //float ib = atof(pextra_widthp.c_str())/100;
3529 // string can't handle floats at present (971109)
3530 // so I'll do a conversion by hand knowing that
3531 // the limits are 0.0 to 1.0. ARRae.
3532 os << "\\begin{LyXParagraphIndent}{";
3533 switch (pextra_widthp.length()) {
3545 os << "\\columnwidth}\n";
3548 eindent_open = true;
3550 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3551 if (pextra_hfill && Previous() &&
3552 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3553 os << "\\hfill{}\n";
3556 if (par_sep == BufferParams::PARSEP_INDENT) {
3557 os << "{\\setlength\\parindent{0pt}\n";
3560 os << "\\begin{minipage}";
3561 switch(pextra_alignment) {
3562 case MINIPAGE_ALIGN_TOP:
3565 case MINIPAGE_ALIGN_MIDDLE:
3568 case MINIPAGE_ALIGN_BOTTOM:
3572 if (!pextra_width.empty()) {
3573 os << '{' << pextra_width << "}\n";
3575 //float ib = atof(par->pextra_width.c_str())/100;
3576 // string can't handle floats at present
3577 // so I'll do a conversion by hand knowing that
3578 // the limits are 0.0 to 1.0. ARRae.
3580 switch (pextra_widthp.length()) {
3592 os << "\\columnwidth}\n";
3595 if (par_sep == BufferParams::PARSEP_INDENT) {
3596 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3599 minipage_open = true;
3600 minipage_open_depth = depth;
3603 #ifdef WITH_WARNINGS
3604 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3605 //I disabled it because it breaks when lists span on several
3608 if (style.isEnvironment()){
3609 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3610 #ifdef FANCY_FOOTNOTE_CODE
3611 if (foot_count < 0) {
3612 // flag that footnote[mark][text] should be
3613 // used for any footnotes from now on
3615 foot_this_level = true;
3618 os << "\\begin{" << style.latexname() << "}{"
3619 << labelwidthstring << "}\n";
3620 } else if (style.labeltype == LABEL_BIBLIO) {
3622 os << "\\begin{" << style.latexname() << "}{"
3623 << bibitemWidthest(current_view->painter())
3625 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3626 #ifdef FANCY_FOOTNOTE_CODE
3627 if (foot_count < 0) {
3628 // flag that footnote[mark][text] should be
3629 // used for any footnotes from now on
3631 foot_this_level = true;
3634 os << "\\begin{" << style.latexname() << '}'
3635 << style.latexparam() << '\n';
3637 os << "\\begin{" << style.latexname() << '}'
3638 << style.latexparam() << '\n';
3641 LyXParagraph * par = this;
3643 par = par->TeXOnePar(os, texrow, false,
3644 foot, foot_texrow, foot_count);
3646 if (minipage_open && par && !style.isEnvironment() &&
3647 (par->pextra_type == PEXTRA_MINIPAGE) &&
3648 par->pextra_start_minipage) {
3649 os << "\\end{minipage}\n";
3651 if (par_sep == BufferParams::PARSEP_INDENT) {
3655 minipage_open = false;
3657 if (par && par->depth > depth) {
3658 if (textclasslist.Style(current_view->buffer()->params.textclass,
3659 par->layout).isParagraph()
3662 // How to handle this? (Lgb)
3663 //&& !suffixIs(os, "\n\n")
3665 // There should be at least one '\n' already
3666 // but we need there to be two for Standard
3667 // paragraphs that are depth-increment'ed to be
3668 // output correctly. However, tables can
3669 // also be paragraphs so don't adjust them.
3672 // Will it ever harm to have one '\n' too
3673 // many? i.e. that we sometimes will have
3674 // three in a row. (Lgb)
3678 par = par->TeXDeeper(os, texrow,
3679 foot, foot_texrow, foot_count);
3681 if (par && par->layout == layout && par->depth == depth &&
3682 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3683 if (par->pextra_hfill && par->Previous() &&
3684 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3685 os << "\\hfill{}\n";
3688 if (par_sep == BufferParams::PARSEP_INDENT) {
3689 os << "{\\setlength\\parindent{0pt}\n";
3692 os << "\\begin{minipage}";
3693 switch(par->pextra_alignment) {
3694 case MINIPAGE_ALIGN_TOP:
3697 case MINIPAGE_ALIGN_MIDDLE:
3700 case MINIPAGE_ALIGN_BOTTOM:
3704 if (!par->pextra_width.empty()) {
3705 os << '{' << par->pextra_width << "}\n";
3707 //float ib = atof(par->pextra_widthp.c_str())/100;
3708 // string can't handle floats at present
3709 // so I'll do a conversion by hand knowing that
3710 // the limits are 0.0 to 1.0. ARRae.
3712 switch (par->pextra_widthp.length()) {
3717 os << "0." << par->pextra_widthp;
3720 os << "0.0" << par->pextra_widthp;
3722 os << "\\columnwidth}\n";
3725 if (par_sep == BufferParams::PARSEP_INDENT) {
3726 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3729 minipage_open = true;
3730 minipage_open_depth = par->depth;
3733 && par->layout == layout
3734 && par->depth == depth
3735 && par->pextra_type == pextra_type
3736 && par->footnoteflag == footnoteflag);
3738 if (style.isEnvironment()) {
3739 os << "\\end{" << style.latexname() << '}';
3740 // maybe this should go after the minipage closes?
3741 if (foot_this_level) {
3742 if (foot_count >= 1) {
3743 if (foot_count > 1) {
3744 os << "\\addtocounter{footnote}{-"
3749 texrow += foot_texrow;
3751 foot_texrow.reset();
3756 if (minipage_open && (minipage_open_depth == depth) &&
3757 (!par || par->pextra_start_minipage ||
3758 par->pextra_type != PEXTRA_MINIPAGE)) {
3759 os << "\\end{minipage}\n";
3761 if (par_sep == BufferParams::PARSEP_INDENT) {
3765 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3766 os << "\\medskip\n\n";
3770 minipage_open = false;
3773 os << "\\end{LyXParagraphIndent}\n";
3776 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3777 && par->pextra_hfill)) {
3781 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3782 return par; // ale970302
3786 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3787 ostream & foot, TexRow & foot_texrow,
3791 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3792 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3793 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3794 "No footnote!" << endl;
3796 LyXParagraph * par = this;
3797 LyXLayout const & style =
3798 textclasslist.Style(current_view->buffer()->params.textclass,
3799 previous->GetLayout());
3801 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3802 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3803 "Float other than footnote in command"
3804 " with moving argument is illegal" << endl;
3807 if (footnotekind != LyXParagraph::FOOTNOTE
3808 && footnotekind != LyXParagraph::MARGIN
3811 // How to solve this?
3812 //&& !suffixIs(file, '\n')
3814 // we need to ensure that real floats like tables and figures
3815 // have their \begin{} on a new line otherwise we can get
3816 // incorrect results when using the endfloat.sty package
3817 // especially if two floats follow one another. ARRae 981022
3818 // NOTE: if the file is length 0 it must have just been
3819 // written out so we assume it ended with a '\n'
3821 // As far as I can see there is never any harm in writing
3822 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3827 bool moving_arg = false;
3828 bool need_closing = false;
3829 bool is_rtl = isRightToLeftPar();
3831 if (is_rtl != parent_is_rtl) {
3836 need_closing = true;
3839 BufferParams * params = ¤t_view->buffer()->params;
3840 bool footer_in_body = true;
3841 switch (footnotekind) {
3842 case LyXParagraph::FOOTNOTE:
3843 if (style.intitle) {
3844 os << "\\thanks{\n";
3845 footer_in_body = false;
3848 if (foot_count == -1) {
3849 // we're at depth 0 so we can use:
3850 os << "\\footnote{%\n";
3851 footer_in_body = false;
3853 os << "\\footnotemark{}%\n";
3855 // we only need this when there are
3856 // multiple footnotes
3857 os << "\\stepcounter{footnote}";
3859 os << "\\footnotetext{%\n";
3860 foot_texrow.start(this, 0);
3861 foot_texrow.newline();
3866 case LyXParagraph::MARGIN:
3867 os << "\\marginpar{\n";
3869 case LyXParagraph::FIG:
3870 if (pextra_type == PEXTRA_FLOATFLT
3871 && (!pextra_width.empty()
3872 || !pextra_widthp.empty())) {
3873 if (!pextra_width.empty())
3874 os << "\\begin{floatingfigure}{"
3875 << pextra_width << "}\n";
3877 os << "\\begin{floatingfigure}{"
3878 << atoi(pextra_widthp.c_str())/100.0
3879 << "\\textwidth}\n";
3881 os << "\\begin{figure}";
3882 if (!params->float_placement.empty()) {
3883 os << '[' << params->float_placement << "]\n";
3889 case LyXParagraph::TAB:
3890 os << "\\begin{table}";
3891 if (!params->float_placement.empty()) {
3892 os << '[' << params->float_placement << "]\n";
3897 case LyXParagraph::WIDE_FIG:
3898 os << "\\begin{figure*}";
3899 if (!params->float_placement.empty()) {
3900 os << '[' << params->float_placement << "]\n";
3905 case LyXParagraph::WIDE_TAB:
3906 os << "\\begin{table*}";
3907 if (!params->float_placement.empty()) {
3908 os << '[' << params->float_placement << "]\n";
3913 case LyXParagraph::ALGORITHM:
3914 os << "\\begin{algorithm}\n";
3919 if (footnotekind != LyXParagraph::FOOTNOTE
3920 || !footer_in_body) {
3921 // Process text for all floats except footnotes in body
3923 LyXLayout const & style =
3925 .Style(current_view->buffer()->params
3929 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3931 if (style.isEnvironment()
3932 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3933 // Allows the use of minipages within float
3934 // environments. Shouldn't be circular because
3935 // we don't support footnotes inside
3936 // floats (yet). ARRae
3937 par = par->TeXEnvironment(os, texrow,
3941 par = par->TeXOnePar(os, texrow, moving_arg,
3946 if (par && !par->IsDummy() && par->depth > depth) {
3947 par = par->TeXDeeper(os, texrow,
3951 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3953 // process footnotes > depth 0 or in environments separately
3954 // NOTE: Currently don't support footnotes within footnotes
3955 // even though that is possible using the \footnotemark
3957 std::ostringstream dummy;
3961 TexRow dummy_texrow;
3962 int dummy_count = 0;
3964 LyXLayout const & style =
3966 .Style(current_view->buffer()->params
3970 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3972 if (style.isEnvironment()
3973 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3974 // Allows the use of minipages within float
3975 // environments. Shouldn't be circular because
3976 // we don't support footnotes inside
3977 // floats (yet). ARRae
3978 par = par->TeXEnvironment(foot, foot_texrow,
3979 dummy, dummy_texrow,
3982 par = par->TeXOnePar(foot, foot_texrow,
3984 dummy, dummy_texrow,
3988 if (par && !par->IsDummy() && par->depth > depth) {
3989 par = par->TeXDeeper(foot, foot_texrow,
3990 dummy, dummy_texrow,
3994 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3996 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3997 "Footnote in a Footnote -- not supported"
4000 #ifndef HAVE_OSTREAM
4001 delete [] dummy.str();
4005 switch (footnotekind) {
4006 case LyXParagraph::FOOTNOTE:
4007 if (footer_in_body) {
4008 // This helps tell which of the multiple
4009 // footnotetexts an error was in.
4011 foot_texrow.newline();
4016 case LyXParagraph::MARGIN:
4019 case LyXParagraph::FIG:
4020 if (pextra_type == PEXTRA_FLOATFLT
4021 && (!pextra_width.empty()
4022 || !pextra_widthp.empty()))
4023 os << "\\end{floatingfigure}";
4025 os << "\\end{figure}";
4027 case LyXParagraph::TAB:
4028 os << "\\end{table}";
4030 case LyXParagraph::WIDE_FIG:
4031 os << "\\end{figure*}";
4033 case LyXParagraph::WIDE_TAB:
4034 os << "\\end{table*}";
4036 case LyXParagraph::ALGORITHM:
4037 os << "\\end{algorithm}";
4044 if (footnotekind != LyXParagraph::FOOTNOTE
4045 && footnotekind != LyXParagraph::MARGIN) {
4046 // we need to ensure that real floats like tables and figures
4047 // have their \end{} on a line of their own otherwise we can
4048 // get incorrect results when using the endfloat.sty package.
4053 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4058 bool LyXParagraph::IsDummy() const
4060 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4061 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4065 void LyXParagraph::SetPExtraType(int type, char const * width,
4066 char const * widthp)
4069 pextra_width = width;
4070 pextra_widthp = widthp;
4072 if (textclasslist.Style(current_view->buffer()->params.textclass,
4073 layout).isEnvironment()) {
4078 while (par && (par->layout == layout)
4079 && (par->depth == depth)) {
4081 par = par->Previous();
4083 par = par->FirstPhysicalPar();
4084 while (par && par->depth > depth) {
4085 par = par->Previous();
4087 par = par->FirstPhysicalPar();
4091 while (par && (par->layout == layout)
4092 && (par->depth == depth)) {
4093 par->pextra_type = type;
4094 par->pextra_width = width;
4095 par->pextra_widthp = widthp;
4096 par = par->NextAfterFootnote();
4097 if (par && (par->depth > depth))
4098 par->SetPExtraType(type, width, widthp);
4099 while (par && ((par->depth > depth) || par->IsDummy()))
4100 par = par->NextAfterFootnote();
4106 void LyXParagraph::UnsetPExtraType()
4108 if (pextra_type == PEXTRA_NONE)
4111 pextra_type = PEXTRA_NONE;
4112 pextra_width.erase();
4113 pextra_widthp.erase();
4115 if (textclasslist.Style(current_view->buffer()->params.textclass,
4116 layout).isEnvironment()) {
4121 while (par && (par->layout == layout)
4122 && (par->depth == depth)) {
4124 par = par->Previous();
4126 par = par->FirstPhysicalPar();
4127 while (par && par->depth > depth) {
4128 par = par->Previous();
4130 par = par->FirstPhysicalPar();
4134 while (par && (par->layout == layout)
4135 && (par->depth == depth)) {
4136 par->pextra_type = PEXTRA_NONE;
4137 par->pextra_width.erase();
4138 par->pextra_widthp.erase();
4139 par = par->NextAfterFootnote();
4140 if (par && (par->depth > depth))
4141 par->UnsetPExtraType();
4142 while (par && ((par->depth > depth) || par->IsDummy()))
4143 par = par->NextAfterFootnote();
4149 bool LyXParagraph::IsHfill(size_type pos) const
4151 return IsHfillChar(GetChar(pos));
4155 bool LyXParagraph::IsInset(size_type pos) const
4157 return IsInsetChar(GetChar(pos));
4161 bool LyXParagraph::IsFloat(size_type pos) const
4163 return IsFloatChar(GetChar(pos));
4167 bool LyXParagraph::IsNewline(size_type pos) const
4169 return pos >= 0 && IsNewlineChar(GetChar(pos));
4173 bool LyXParagraph::IsSeparator(size_type pos) const
4175 return IsSeparatorChar(GetChar(pos));
4179 bool LyXParagraph::IsLineSeparator(size_type pos) const
4181 return IsLineSeparatorChar(GetChar(pos));
4185 bool LyXParagraph::IsKomma(size_type pos) const
4187 return IsKommaChar(GetChar(pos));
4191 /// Used by the spellchecker
4192 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4194 unsigned char c = GetChar(pos);
4195 if (IsLetterChar(c))
4197 // '\0' is not a letter, allthough every string contains "" (below)
4200 // We want to pass the ' and escape chars to ispell
4201 string extra = lyxrc.isp_esc_chars + '\'';
4205 return contains(extra, ch);
4209 bool LyXParagraph::IsWord(size_type pos ) const
4211 return IsWordChar(GetChar(pos)) ;
4215 Language const * LyXParagraph::getParLanguage() const
4219 return FirstPhysicalPar()->GetFirstFontSettings()
4222 for (size_type pos = 0; pos < size(); ++pos)
4224 return GetFontSettings(pos).language();
4225 return GetFirstFontSettings().language();
4228 return previous->getParLanguage();
4230 return current_view->buffer()->params.language_info;
4234 bool LyXParagraph::isRightToLeftPar() const
4236 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4240 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4242 for(size_type i = 0; i < size(); ++i) {
4243 LyXFont font = GetFontSettings(i);
4244 if (font.language() == from) {
4245 font.setLanguage(to);
4252 bool LyXParagraph::isMultiLingual()
4254 Language const * doc_language =
4255 current_view->buffer()->params.language_info;
4256 for(size_type i = 0; i < size(); ++i) {
4257 LyXFont font = GetFontSettings(i);
4258 if (font.language() != doc_language)