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 lyxerr << "CODE: << " << inset->LyxCode() << endl;
669 return inset_owner->InsertInsetAllowed(inset);
675 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
679 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
680 return NextAfterFootnote()
681 ->GetInset(pos - text.size() - 1);
683 lyxerr << "ERROR (LyXParagraph::GetInset): "
684 "position does not exist: "
690 InsetList::iterator it = lower_bound(insetlist.begin(),
693 if (it != insetlist.end() && (*it).pos == pos)
696 lyxerr << "ERROR (LyXParagraph::GetInset): "
697 "Inset does not exist: " << pos << endl;
698 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
699 // Did this commenting out introduce a bug? So far I have not
700 // see any, please enlighten me. (Lgb)
701 // My guess is that since the inset does not exist, we might
702 // as well replace it with a space to prevent craches. (Asger)
707 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
711 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
712 return NextAfterFootnote()
713 ->GetInset(pos - text.size() - 1);
715 lyxerr << "ERROR (LyXParagraph::GetInset): "
716 "position does not exist: "
722 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
725 if (cit != insetlist.end() && (*cit).pos == pos)
728 lyxerr << "ERROR (LyXParagraph::GetInset): "
729 "Inset does not exist: " << pos << endl;
730 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
731 // Did this commenting out introduce a bug? So far I have not
732 // see any, please enlighten me. (Lgb)
733 // My guess is that since the inset does not exist, we might
734 // as well replace it with a space to prevent craches. (Asger)
739 // Gets uninstantiated font setting at position.
740 // Optimized after profiling. (Asger)
741 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
744 #ifdef SORTED_FONT_LIST
745 for (FontList::const_iterator cit = fontlist.begin();
746 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
747 if (pos >= (*cit).pos)
750 for (FontList::const_iterator cit = fontlist.begin();
751 cit != fontlist.end(); ++cit)
752 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
756 // > because last is the next unused position, and you can
757 // use it if you want
758 else if (pos > size()) {
760 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
761 return NextAfterFootnote()
762 ->GetFontSettings(pos - text.size() - 1);
764 // Why is it an error to ask for the font of a
765 // position that does not exist? Would it be
766 // enough for this to be enabled on debug?
767 // We want strict error checking, but it's ok to only
768 // have it when debugging. (Asger)
769 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
770 "position does not exist. "
771 << pos << " (" << static_cast<int>(pos)
774 } else if (pos > 0) {
775 return GetFontSettings(pos - 1);
776 } else // pos = size() = 0
777 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
779 return LyXFont(LyXFont::ALL_INHERIT);
782 // Gets uninstantiated font setting at position 0
783 LyXFont LyXParagraph::GetFirstFontSettings() const
786 #ifdef SORTED_FONT_LIST
787 if (!fontlist.empty() && fontlist.front().pos == 0)
788 return fontlist.front().font;
790 for (FontList::const_iterator cit = fontlist.begin();
791 cit != fontlist.end(); ++cit)
792 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
795 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
796 return NextAfterFootnote()->GetFirstFontSettings();
797 return LyXFont(LyXFont::ALL_INHERIT);
800 // Gets the fully instantiated font at a given position in a paragraph
801 // This is basically the same function as LyXText::GetFont() in text2.C.
802 // The difference is that this one is used for generating the LaTeX file,
803 // and thus cosmetic "improvements" are disallowed: This has to deliver
804 // the true picture of the buffer. (Asger)
805 // If position is -1, we get the layout font of the paragraph.
806 // If position is -2, we get the font of the manual label of the paragraph.
807 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
810 LyXLayout const & layout =
811 textclasslist.Style(current_view->buffer()->params.textclass,
813 LyXParagraph::size_type main_body = 0;
814 if (layout.labeltype == LABEL_MANUAL)
815 main_body = BeginningOfMainBody();
820 layoutfont = layout.labelfont;
822 layoutfont = layout.font;
823 tmpfont = GetFontSettings(pos);
824 tmpfont.realize(layoutfont);
826 // process layoutfont for pos == -1 and labelfont for pos < -1
828 tmpfont = layout.font;
830 tmpfont = layout.labelfont;
831 tmpfont.setLanguage(getParLanguage());
834 // check for environment font information
835 char par_depth = GetDepth();
836 LyXParagraph const * par = this;
837 while (par && par_depth && !tmpfont.resolved()) {
838 par = par->DepthHook(par_depth - 1);
840 tmpfont.realize(textclasslist.
841 Style(current_view->buffer()->params.textclass,
842 par->GetLayout()).font);
843 par_depth = par->GetDepth();
847 tmpfont.realize(textclasslist
848 .TextClass(current_view->buffer()->params.textclass)
854 /// Returns the height of the highest font in range
856 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
857 LyXParagraph::size_type endpos) const
859 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
860 for (FontList::const_iterator cit = fontlist.begin();
861 cit != fontlist.end(); ++cit) {
862 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
863 LyXFont::FONT_SIZE size = (*cit).font.size();
864 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
872 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
879 // > because last is the next unused position, and you can
880 // use it if you want
881 else if (pos > size()) {
882 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
883 return NextAfterFootnote()
884 ->GetChar(pos - text.size() - 1);
886 lyxerr << "ERROR (LyXParagraph::GetChar): "
887 "position does not exist."
888 << pos << " (" << static_cast<int>(pos)
890 // Assert(false); // This triggers sometimes...
895 // We should have a footnote environment.
896 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
897 // Notice that LyX does request the
898 // last char from time to time. (Asger)
899 //lyxerr << "ERROR (LyXParagraph::GetChar): "
900 // "expected footnote." << endl;
903 switch (next->footnotekind) {
904 case LyXParagraph::FOOTNOTE:
905 return LyXParagraph::META_FOOTNOTE;
906 case LyXParagraph::MARGIN:
907 return LyXParagraph::META_MARGIN;
908 case LyXParagraph::FIG:
909 case LyXParagraph::WIDE_FIG:
910 return LyXParagraph::META_FIG;
911 case LyXParagraph::TAB:
912 case LyXParagraph::WIDE_TAB:
913 return LyXParagraph::META_TAB;
914 case LyXParagraph::ALGORITHM:
915 return LyXParagraph::META_ALGORITHM;
917 return '\0'; // to shut up gcc
922 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
929 // > because last is the next unused position, and you can
930 // use it if you want
931 else if (pos > size()) {
932 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
933 return NextAfterFootnote()
934 ->GetChar(pos - text.size() - 1);
936 lyxerr << "ERROR (LyXParagraph::GetChar const): "
937 "position does not exist."
938 << pos << " (" << static_cast<int>(pos)
944 // We should have a footnote environment.
945 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
946 // Notice that LyX does request the
947 // last char from time to time. (Asger)
948 //lyxerr << "ERROR (LyXParagraph::GetChar): "
949 // "expected footnote." << endl;
952 switch (next->footnotekind) {
953 case LyXParagraph::FOOTNOTE:
954 return LyXParagraph::META_FOOTNOTE;
955 case LyXParagraph::MARGIN:
956 return LyXParagraph::META_MARGIN;
957 case LyXParagraph::FIG:
958 case LyXParagraph::WIDE_FIG:
959 return LyXParagraph::META_FIG;
960 case LyXParagraph::TAB:
961 case LyXParagraph::WIDE_TAB:
962 return LyXParagraph::META_TAB;
963 case LyXParagraph::ALGORITHM:
964 return LyXParagraph::META_ALGORITHM;
966 return '\0'; // to shut up gcc
971 // return an string of the current word, and the end of the word in lastpos.
972 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
976 // the current word is defined as starting at the first character
977 // from the immediate left of lastpospos which meets the definition
978 // of IsLetter(), continuing to the last character to the right
979 // of this meeting IsLetter.
985 // move back until we have a letter
987 //there's no real reason to have firstpos & lastpos as
988 //separate variables as this is written, but maybe someon
989 // will want to return firstpos in the future.
991 //since someone might have typed a punctuation first
992 int firstpos = lastpos;
994 while ((firstpos >= 0) && !IsLetter(firstpos))
997 // now find the beginning by looking for a nonletter
999 while ((firstpos>= 0) && IsLetter(firstpos))
1002 // the above is now pointing to the preceeding non-letter
1006 // so copy characters into theword until we get a nonletter
1007 // note that this can easily exceed lastpos, wich means
1008 // that if used in the middle of a word, the whole word
1011 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1018 LyXParagraph::size_type LyXParagraph::Last() const
1020 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1021 return text.size() + NextAfterFootnote()->Last() + 1;
1022 // the 1 is the symbol
1029 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1031 // > because last is the next unused position, and you can
1032 // use it if you want
1035 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1036 return NextAfterFootnote()
1037 ->ParFromPos(pos - text.size() - 1);
1039 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1040 "position does not exist." << endl;
1047 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1049 // > because last is the next unused position, and you can
1050 // use it if you want
1053 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1054 return NextAfterFootnote()
1055 ->PositionInParFromPos(pos - text.size() - 1);
1058 "ERROR (LyXParagraph::PositionInParFromPos): "
1059 "position does not exist." << endl;
1067 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1068 LyXFont const & font)
1070 // > because last is the next unused position, and you can
1071 // use it if you want
1074 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1075 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1078 lyxerr << "ERROR (LyXParagraph::SetFont): "
1079 "position does not exist." << endl;
1083 LyXFont patternfont(LyXFont::ALL_INHERIT);
1085 // First, reduce font against layout/label font
1086 // Update: The SetCharFont() routine in text2.C already
1087 // reduces font, so we don't need to do that here. (Asger)
1088 // No need to simplify this because it will disappear
1089 // in a new kernel. (Asger)
1090 // Next search font table
1091 FontList::iterator tmp = fontlist.begin();
1092 for (; tmp != fontlist.end(); ++tmp) {
1093 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1097 if (tmp == fontlist.end()) { // !found
1098 // if we did not find a font entry, but if the font at hand
1099 // is the same as default, we just forget it
1100 if (font == patternfont) return;
1102 // ok, we did not find a font entry. But maybe there is exactly
1103 // the needed font ientry one position left
1104 FontList::iterator tmp2 = fontlist.begin();
1105 for (; tmp2 != fontlist.end(); ++tmp2) {
1106 if (pos - 1 >= (*tmp2).pos
1107 && pos - 1 <= (*tmp2).pos_end)
1110 if (tmp2 != fontlist.end()) {
1111 // ok there is one, maybe it is exactly
1113 if ((*tmp2).font == font) {
1114 // put the position under the font
1119 // Add a new entry in the
1120 // fontlist for the position
1124 ft.font = font; // or patternfont
1125 // It seems that using font instead of patternfont here
1126 // fixes all the problems. This also surfaces a "bug" in
1128 fontlist.insert(fontlist.begin(), ft);
1129 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1131 // more than one character
1132 if (pos == (*tmp).pos) {
1133 // maybe we should enlarge the left fonttable
1134 FontList::iterator tmp2 = fontlist.begin();
1135 for (; tmp2 != fontlist.end(); ++tmp2) {
1136 if (pos - 1 >= (*tmp2).pos
1137 && pos - 1 <= (*tmp2).pos_end)
1140 // Is there is one, and is it exactly
1142 if (tmp2 != fontlist.end() &&
1143 (*tmp2).font == font) {
1144 // Put the position under the font
1150 // Add a new entry in the
1151 // fontlist for the position
1154 ft.pos_end = (*tmp).pos_end;
1155 ft.font = (*tmp).font;
1156 (*tmp).pos_end = pos;
1158 fontlist.insert(fontlist.begin(), ft);
1159 } else if (pos == (*tmp).pos_end) {
1160 // Add a new entry in the
1161 // fontlist for the position
1163 ft.pos = (*tmp).pos;
1164 ft.pos_end = (*tmp).pos_end - 1;
1165 ft.font = (*tmp).font;
1166 (*tmp).pos = (*tmp).pos_end;
1168 fontlist.insert(fontlist.begin(), ft);
1170 // Add a new entry in the
1171 // fontlist for the position
1173 ft.pos = (*tmp).pos;
1174 ft.pos_end = pos - 1;
1175 ft.font = (*tmp).font;
1179 ft2.pos_end = (*tmp).pos_end;
1180 ft2.font = (*tmp).font;
1183 (*tmp).pos_end = pos;
1186 fontlist.insert(fontlist.begin(), ft);
1187 fontlist.insert(fontlist.begin(), ft2);
1195 // This function is able to hide closed footnotes.
1196 LyXParagraph * LyXParagraph::Next()
1198 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1199 LyXParagraph * tmp = next;
1201 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1203 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1204 return tmp->Next(); /* there can be more than one
1205 footnote in a logical
1208 return next; // This should never happen!
1214 LyXParagraph * LyXParagraph::NextAfterFootnote()
1216 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1217 LyXParagraph * tmp = next;
1218 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1220 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1221 return tmp; /* there can be more than one footnote
1222 in a logical paragraph */
1224 return next; // This should never happen!
1230 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1232 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1233 LyXParagraph * tmp = next;
1234 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1236 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1237 return tmp; /* there can be more than one footnote
1238 in a logical paragraph */
1240 return next; // This should never happen!
1246 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1249 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1251 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1252 tmp = tmp->previous;
1253 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1254 return tmp; /* there can be more than one footnote
1255 in a logical paragraph */
1257 return previous; // This should never happen!
1263 LyXParagraph * LyXParagraph::LastPhysicalPar()
1265 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1268 LyXParagraph * tmp = this;
1270 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1271 tmp = tmp->NextAfterFootnote();
1276 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1278 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1281 LyXParagraph const * tmp = this;
1283 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1284 tmp = tmp->NextAfterFootnote();
1289 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1293 LyXParagraph * tmppar = this;
1297 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1298 tmppar = tmppar->previous;
1307 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1311 LyXParagraph const * tmppar = this;
1315 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1316 tmppar = tmppar->previous;
1325 // This function is able to hide closed footnotes.
1326 LyXParagraph * LyXParagraph::Previous()
1328 LyXParagraph * tmp = previous;
1333 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1334 tmp = tmp->previous;
1336 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1337 tmp = tmp->previous;
1338 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1339 return tmp->next->Previous();
1348 // This function is able to hide closed footnotes.
1349 LyXParagraph const * LyXParagraph::Previous() const
1351 LyXParagraph * tmp = previous;
1356 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1357 tmp = tmp->previous;
1359 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1360 tmp = tmp->previous;
1361 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1362 return tmp->next->Previous();
1371 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1374 size_type i, j, pos_end, pos_first;
1375 // create a new paragraph
1376 LyXParagraph * par = ParFromPos(pos);
1377 LyXParagraph * firstpar = FirstPhysicalPar();
1379 LyXParagraph * tmp = new LyXParagraph(par);
1381 tmp->footnoteflag = footnoteflag;
1382 tmp->footnotekind = footnotekind;
1384 // this is an idea for a more userfriendly layout handling, I will
1385 // see what the users say
1387 // layout stays the same with latex-environments
1389 tmp->SetOnlyLayout(firstpar->layout);
1390 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1393 if (Last() > pos || !Last() || flag == 2) {
1394 tmp->SetOnlyLayout(firstpar->layout);
1395 tmp->align = firstpar->align;
1396 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1398 tmp->line_bottom = firstpar->line_bottom;
1399 firstpar->line_bottom = false;
1400 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1401 firstpar->pagebreak_bottom = false;
1402 tmp->added_space_bottom = firstpar->added_space_bottom;
1403 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1405 tmp->depth = firstpar->depth;
1406 tmp->noindent = firstpar->noindent;
1408 // copy everything behind the break-position
1409 // to the new paragraph
1411 while (ParFromPos(pos_first) != par)
1414 pos_end = pos_first + par->text.size() - 1;
1416 for (i = j = pos; i <= pos_end; ++i) {
1417 par->CutIntoMinibuffer(i - pos_first);
1418 if (tmp->InsertFromMinibuffer(j - pos))
1421 tmp->text.resize(tmp->text.size());
1422 for (i = pos_end; i >= pos; --i)
1423 par->Erase(i - pos_first);
1425 par->text.resize(par->text.size());
1428 // just an idea of me
1430 tmp->line_top = firstpar->line_top;
1431 tmp->pagebreak_top = firstpar->pagebreak_top;
1432 tmp->added_space_top = firstpar->added_space_top;
1433 tmp->bibkey = firstpar->bibkey;
1435 // layout stays the same with latex-environments
1437 firstpar->SetOnlyLayout(tmp->layout);
1438 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1439 firstpar->depth = tmp->depth;
1445 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1447 par = par->FirstPhysicalPar();
1448 footnoteflag = par->footnoteflag;
1449 footnotekind = par->footnotekind;
1451 layout = par->layout;
1452 align = par-> align;
1453 SetLabelWidthString(par->labelwidthstring);
1455 line_bottom = par->line_bottom;
1456 pagebreak_bottom = par->pagebreak_bottom;
1457 added_space_bottom = par->added_space_bottom;
1459 line_top = par->line_top;
1460 pagebreak_top = par->pagebreak_top;
1461 added_space_top = par->added_space_top;
1463 spacing = par->spacing;
1465 pextra_type = par->pextra_type;
1466 pextra_width = par->pextra_width;
1467 pextra_widthp = par->pextra_widthp;
1468 pextra_alignment = par->pextra_alignment;
1469 pextra_hfill = par->pextra_hfill;
1470 pextra_start_minipage = par->pextra_start_minipage;
1472 noindent = par->noindent;
1477 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1479 LyXParagraph * tmppar = this;
1482 && tmppar->previous->footnoteflag ==
1483 LyXParagraph::CLOSED_FOOTNOTE)
1484 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1485 tmppar = tmppar->previous;
1488 return this; // This should never happen!
1494 LyXParagraph * LyXParagraph::Clone() const
1496 // create a new paragraph
1497 LyXParagraph * result = new LyXParagraph;
1499 result->MakeSameLayout(this);
1501 // this is because of the dummy layout of the paragraphs that
1503 result->layout = layout;
1505 /* table stuff -- begin*/
1507 result->table = table->Clone();
1510 /* table stuff -- end*/
1512 result->inset_owner = inset_owner;
1515 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1518 // copy everything behind the break-position to the new paragraph
1520 result->text = text;
1521 result->fontlist = fontlist;
1522 result->insetlist = insetlist;
1523 for (InsetList::iterator it = result->insetlist.begin();
1524 it != result->insetlist.end(); ++it)
1525 (*it).inset = (*it).inset->Clone();
1530 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1532 par = par->FirstPhysicalPar();
1535 par->footnoteflag == footnoteflag &&
1536 par->footnotekind == footnotekind &&
1538 par->layout == layout &&
1540 par->align == align &&
1542 par->line_bottom == line_bottom &&
1543 par->pagebreak_bottom == pagebreak_bottom &&
1544 par->added_space_bottom == added_space_bottom &&
1546 par->line_top == line_top &&
1547 par->pagebreak_top == pagebreak_top &&
1548 par->added_space_top == added_space_top &&
1550 par->spacing == spacing &&
1552 par->pextra_type == pextra_type &&
1553 par->pextra_width == pextra_width &&
1554 par->pextra_widthp == pextra_widthp &&
1555 par->pextra_alignment == pextra_alignment &&
1556 par->pextra_hfill == pextra_hfill &&
1557 par->pextra_start_minipage == pextra_start_minipage &&
1559 par->table == table && // what means: NO TABLE AT ALL
1561 par->noindent == noindent &&
1562 par->depth == depth);
1566 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1568 // create a new paragraph
1569 LyXParagraph * par = ParFromPos(pos);
1571 LyXParagraph * tmp = new LyXParagraph(par);
1573 tmp->MakeSameLayout(par);
1575 // When can pos < Last()?
1576 // I guess pos == Last() is possible.
1578 // copy everything behind the break-position to the new
1580 size_type pos_first = 0;
1581 while (ParFromPos(pos_first) != par)
1583 size_type pos_end = pos_first + par->text.size() - 1;
1586 for (i = j = pos; i <= pos_end; ++i) {
1587 par->CutIntoMinibuffer(i - pos_first);
1588 if (tmp->InsertFromMinibuffer(j - pos))
1591 tmp->text.resize(tmp->text.size());
1592 for (size_type i = pos_end; i >= pos; --i)
1593 par->Erase(i - pos_first);
1595 par->text.resize(par->text.size());
1600 // Be carefull, this does not make any check at all.
1601 void LyXParagraph::PasteParagraph()
1603 // copy the next paragraph to this one
1604 LyXParagraph * the_next = Next();
1606 LyXParagraph * firstpar = FirstPhysicalPar();
1608 // first the DTP-stuff
1609 firstpar->line_bottom = the_next->line_bottom;
1610 firstpar->added_space_bottom = the_next->added_space_bottom;
1611 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1613 size_type pos_end = the_next->text.size() - 1;
1614 size_type pos_insert = Last();
1616 // ok, now copy the paragraph
1618 for (i = j = 0; i <= pos_end; ++i) {
1619 the_next->CutIntoMinibuffer(i);
1620 if (InsertFromMinibuffer(pos_insert + j))
1624 // delete the next paragraph
1629 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1631 LyXParagraph * par = ParFromPos(pos);
1633 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1634 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1640 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1642 LyXParagraph * par = ParFromPos(pos);
1644 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1645 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1650 int LyXParagraph::GetEndLabel() const
1652 LyXParagraph const * par = this;
1653 int par_depth = GetDepth();
1655 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1657 textclasslist.Style(current_view->buffer()->params.textclass,
1658 layout).endlabeltype;
1659 if (endlabeltype != END_LABEL_NO_LABEL) {
1660 LyXParagraph const * last = this;
1661 if( footnoteflag == NO_FOOTNOTE)
1662 last = LastPhysicalPar();
1663 else if (next->footnoteflag == NO_FOOTNOTE)
1664 return endlabeltype;
1666 if (!last || !last->next)
1667 return endlabeltype;
1669 int next_depth = last->next->GetDepth();
1670 if (par_depth > next_depth ||
1671 (par_depth == next_depth && layout != last->next->GetLayout() ))
1672 return endlabeltype;
1677 par = par->DepthHook(par_depth - 1);
1679 par_depth = par->GetDepth();
1681 return END_LABEL_NO_LABEL;
1685 LyXTextClass::size_type LyXParagraph::GetLayout() const
1687 return FirstPhysicalPar()->layout;
1691 char LyXParagraph::GetDepth() const
1693 return FirstPhysicalPar()->depth;
1697 char LyXParagraph::GetAlign() const
1699 return FirstPhysicalPar()->align;
1703 string LyXParagraph::GetLabelstring() const
1705 return FirstPhysicalPar()->labelstring;
1709 int LyXParagraph::GetFirstCounter(int i) const
1711 return FirstPhysicalPar()->counter_[i];
1715 // the next two functions are for the manual labels
1716 string LyXParagraph::GetLabelWidthString() const
1718 if (!FirstPhysicalPar()->labelwidthstring.empty())
1719 return FirstPhysicalPar()->labelwidthstring;
1721 return _("Senseless with this layout!");
1725 void LyXParagraph::SetLabelWidthString(string const & s)
1727 LyXParagraph * par = FirstPhysicalPar();
1729 par->labelwidthstring = s;
1733 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1735 LyXParagraph * par = FirstPhysicalPar();
1736 LyXParagraph * ppar = 0;
1737 LyXParagraph * npar = 0;
1739 par->layout = new_layout;
1740 /* table stuff -- begin*/
1743 /* table stuff -- end*/
1744 if (par->pextra_type == PEXTRA_NONE) {
1745 if (par->Previous()) {
1746 ppar = par->Previous()->FirstPhysicalPar();
1749 && (ppar->depth > par->depth))
1750 ppar = ppar->Previous()->FirstPhysicalPar();
1753 npar = par->Next()->NextAfterFootnote();
1756 && (npar->depth > par->depth))
1757 npar = npar->Next()->NextAfterFootnote();
1759 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1761 p1 = ppar->pextra_width,
1762 p2 = ppar->pextra_widthp;
1763 ppar->SetPExtraType(ppar->pextra_type,
1764 p1.c_str(), p2.c_str());
1766 if ((par->pextra_type == PEXTRA_NONE) &&
1767 npar && (npar->pextra_type != PEXTRA_NONE)) {
1769 p1 = npar->pextra_width,
1770 p2 = npar->pextra_widthp;
1771 npar->SetPExtraType(npar->pextra_type,
1772 p1.c_str(), p2.c_str());
1778 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1781 * par = FirstPhysicalPar(),
1785 par->layout = new_layout;
1786 par->labelwidthstring.erase();
1787 par->align = LYX_ALIGN_LAYOUT;
1788 par->added_space_top = VSpace(VSpace::NONE);
1789 par->added_space_bottom = VSpace(VSpace::NONE);
1790 par->spacing.set(Spacing::Default);
1792 /* table stuff -- begin*/
1795 /* table stuff -- end*/
1796 if (par->pextra_type == PEXTRA_NONE) {
1797 if (par->Previous()) {
1798 ppar = par->Previous()->FirstPhysicalPar();
1801 && (ppar->depth > par->depth))
1802 ppar = ppar->Previous()->FirstPhysicalPar();
1805 npar = par->Next()->NextAfterFootnote();
1808 && (npar->depth > par->depth))
1809 npar = npar->Next()->NextAfterFootnote();
1811 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1813 p1 = ppar->pextra_width,
1814 p2 = ppar->pextra_widthp;
1815 ppar->SetPExtraType(ppar->pextra_type,
1816 p1.c_str(), p2.c_str());
1818 if ((par->pextra_type == PEXTRA_NONE) &&
1819 npar && (npar->pextra_type != PEXTRA_NONE)) {
1821 p1 = npar->pextra_width,
1822 p2 = npar->pextra_widthp;
1823 npar->SetPExtraType(npar->pextra_type,
1824 p1.c_str(), p2.c_str());
1830 // if the layout of a paragraph contains a manual label, the beginning of the
1831 // main body is the beginning of the second word. This is what the par-
1832 // function returns. If the layout does not contain a label, the main
1833 // body always starts with position 0. This differentiation is necessary,
1834 // because there cannot be a newline or a blank <= the beginning of the
1835 // main body in TeX.
1837 int LyXParagraph::BeginningOfMainBody() const
1839 if (FirstPhysicalPar() != this)
1842 // Unroll the first two cycles of the loop
1843 // and remember the previous character to
1844 // remove unnecessary GetChar() calls
1847 && GetChar(i) != LyXParagraph::META_NEWLINE
1850 char previous_char = 0, temp = 0;
1852 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1853 // Yes, this ^ is supposed to be "= " not "=="
1856 && previous_char != ' '
1857 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1859 previous_char = temp;
1864 if (i == 0 && i == size() &&
1865 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1866 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1867 ++i; /* the cursor should not jump
1868 * to the main body if there
1874 LyXParagraph * LyXParagraph::DepthHook(int deth)
1876 LyXParagraph * newpar = this;
1881 newpar = newpar->FirstPhysicalPar()->Previous();
1882 } while (newpar && newpar->GetDepth() > deth
1883 && newpar->footnoteflag == footnoteflag);
1886 if (Previous() || GetDepth())
1887 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1891 return newpar->FirstPhysicalPar();
1895 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1897 LyXParagraph const * newpar = this;
1902 newpar = newpar->FirstPhysicalPar()->Previous();
1903 } while (newpar && newpar->GetDepth() > deth
1904 && newpar->footnoteflag == footnoteflag);
1907 if (Previous() || GetDepth())
1908 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1912 return newpar->FirstPhysicalPar();
1916 int LyXParagraph::AutoDeleteInsets()
1919 InsetList::size_type index = 0;
1920 while (index < insetlist.size()) {
1921 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1922 Erase(insetlist[index].pos);
1923 // Erase() calls to insetlist.erase(&insetlist[index])
1924 // so index shouldn't be increased.
1933 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1935 InsetList::iterator it = lower_bound(insetlist.begin(),
1938 if (it != insetlist.end()) {
1946 // returns -1 if inset not found
1947 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1950 // We could use lower_bound here too, we just need to add
1951 // the approp. operator() to matchIT (and change the name
1952 // of that struct). Code would then be:
1953 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1955 // inset, matchIT());
1956 // if ((*cit).inset == inset) {
1957 // return (*cit).pos;
1959 for (InsetList::const_iterator cit = insetlist.begin();
1960 cit != insetlist.end(); ++cit) {
1961 if ((*cit).inset == inset) {
1965 // Think about footnotes.
1966 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1967 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1969 NextAfterFootnote()->GetPositionOfInset(inset);
1971 return text.size() + 1 + further;
1977 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1980 TexRow & foot_texrow,
1983 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1984 LyXLayout const & style =
1985 textclasslist.Style(current_view->buffer()->params.textclass,
1988 bool further_blank_line = false;
1990 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1992 if (start_of_appendix) {
1993 os << "\\appendix\n";
1997 if (!spacing.isDefault()
1998 && (!Previous() || !Previous()->HasSameLayout(this))) {
1999 os << spacing.writeEnvirBegin() << "\n";
2003 if (tex_code_break_column && style.isCommand()){
2008 if (pagebreak_top) {
2010 further_blank_line = true;
2012 if (added_space_top.kind() != VSpace::NONE) {
2013 os << added_space_top.asLatexCommand(current_view->buffer()->params);
2014 further_blank_line = true;
2018 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2019 << "\\vspace{-1\\parskip}";
2020 further_blank_line = true;
2023 if (further_blank_line){
2028 Language const * language = getParLanguage();
2029 Language const * doc_language = current_view->buffer()->params.language_info;
2030 if (language != doc_language) {
2031 os << subst(lyxrc.language_command_begin, "$$lang",
2037 switch (style.latextype) {
2040 << style.latexname()
2041 << style.latexparam();
2043 case LATEX_ITEM_ENVIRONMENT:
2045 bibkey->Latex(os, false, false);
2049 case LATEX_LIST_ENVIRONMENT:
2056 bool need_par = SimpleTeXOnePar(os, texrow, moving_arg);
2058 // Spit out footnotes
2059 LyXParagraph * par = next;
2060 if (lyxrc.rtl_support) {
2061 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2062 && next->footnoteflag != footnoteflag) {
2063 LyXParagraph * p = 0;
2064 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2065 if ( (p = NextAfterFootnote()) != 0 &&
2066 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2067 is_rtl = GetFontSettings(0).isRightToLeft();
2069 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2070 par->footnoteflag != footnoteflag) {
2071 par = par->TeXFootnote(os, texrow, foot,
2072 foot_texrow, foot_count,
2074 par->SimpleTeXOnePar(os, texrow, moving_arg);
2075 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2077 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2078 (p = par->NextAfterFootnote()) != 0 &&
2079 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2080 is_rtl = GetFontSettings(0).isRightToLeft();
2085 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2086 && par->footnoteflag != footnoteflag) {
2087 par = par->TeXFootnote(os, texrow,
2088 foot, foot_texrow, foot_count,
2090 par->SimpleTeXOnePar(os, texrow, moving_arg);
2095 // Make sure that \\par is done with the font of the last
2096 // character if this has another size as the default.
2097 // This is necessary because LaTeX (and LyX on the screen)
2098 // calculates the space between the baselines according
2099 // to this font. (Matthias)
2100 LyXFont font = getFont(Last() - 1);
2102 if (style.resfont.size() != font.size()) {
2108 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2109 GetLayout()).isCommand()){
2110 if (style.resfont.size() != font.size()) {
2116 } else if (style.resfont.size() != font.size()){
2117 os << "{\\" << font.latexSize() << " \\par}";
2120 if (language != doc_language) {
2122 << subst(lyxrc.language_command_end, "$$lang",
2123 doc_language->lang);
2126 switch (style.latextype) {
2127 case LATEX_ITEM_ENVIRONMENT:
2128 case LATEX_LIST_ENVIRONMENT:
2129 if (par && (depth < par->depth)) {
2134 case LATEX_ENVIRONMENT:
2135 // if its the last paragraph of the current environment
2136 // skip it otherwise fall through
2138 && (par->layout != layout
2139 || par->depth != depth
2140 || par->pextra_type != pextra_type))
2143 // we don't need it for the last paragraph!!!
2144 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2145 && footnotekind != LyXParagraph::FOOTNOTE
2146 && footnotekind != LyXParagraph::MARGIN
2150 // don't insert this if we would be adding it
2151 // before or after a table in a float. This
2152 // little trick is needed in order to allow
2153 // use of tables in \subfigures or \subtables.
2159 further_blank_line = false;
2161 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2162 further_blank_line = true;
2165 if (added_space_bottom.kind() != VSpace::NONE) {
2166 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2167 further_blank_line = true;
2170 if (pagebreak_bottom) {
2172 further_blank_line = true;
2175 if (further_blank_line){
2180 if (!spacing.isDefault()
2181 && (!par || !par->HasSameLayout(this))) {
2182 os << spacing.writeEnvirEnd() << "\n";
2186 // we don't need it for the last paragraph!!!
2187 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2188 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2193 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2198 // This one spits out the text of the paragraph
2199 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow,
2202 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2205 return SimpleTeXOneTablePar(os, texrow);
2207 bool return_value = false;
2209 LyXLayout const & style =
2210 textclasslist.Style(current_view->buffer()->params.textclass,
2212 LyXFont basefont, last_font;
2214 // Maybe we have to create a optional argument.
2215 size_type main_body;
2216 if (style.labeltype != LABEL_MANUAL)
2219 main_body = BeginningOfMainBody();
2221 if (main_body > 0) {
2223 basefont = getFont(-2); // Get label font
2225 basefont = getFont(-1); // Get layout font
2233 if (style.isCommand()) {
2236 } else if (align != LYX_ALIGN_LAYOUT) {
2239 return_value = true;
2243 moving_arg |= style.needprotect;
2245 // Which font is currently active?
2246 LyXFont running_font(basefont);
2247 // Do we have an open font change?
2248 bool open_font = false;
2250 texrow.start(this, 0);
2252 for (size_type i = 0; i < size(); ++i) {
2254 // First char in paragraph or after label?
2255 if (i == main_body && !IsDummy()) {
2256 if (main_body > 0) {
2258 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2261 basefont = getFont(-1); // Now use the layout font
2262 running_font = basefont;
2266 if (style.isCommand()) {
2269 } else if (align != LYX_ALIGN_LAYOUT) {
2272 return_value = true;
2276 os << "\\noindent ";
2280 case LYX_ALIGN_NONE:
2281 case LYX_ALIGN_BLOCK:
2282 case LYX_ALIGN_LAYOUT:
2283 case LYX_ALIGN_SPECIAL:
2285 case LYX_ALIGN_LEFT:
2286 if (getParLanguage()->lang != "hebrew") {
2287 os << "\\raggedright ";
2290 os << "\\raggedleft ";
2294 case LYX_ALIGN_RIGHT:
2295 if (getParLanguage()->lang != "hebrew") {
2296 os << "\\raggedleft ";
2299 os << "\\raggedright ";
2303 case LYX_ALIGN_CENTER:
2304 os << "\\centering ";
2312 // Fully instantiated font
2313 LyXFont font = getFont(i);
2314 LyXParagraph * p = 0;
2315 if (i == 0 && previous &&
2316 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2317 (p = PreviousBeforeFootnote()) != 0)
2318 last_font = p->getFont(p->size()-1);
2320 last_font = running_font;
2322 // Spaces at end of font change are simulated to be
2323 // outside font change, i.e. we write "\textXX{text} "
2324 // rather than "\textXX{text }". (Asger)
2325 if (open_font && c == ' ' && i <= size() - 2
2326 && !getFont(i+1).equalExceptLatex(running_font)
2327 && !getFont(i+1).equalExceptLatex(font)) {
2328 font = getFont(i + 1);
2330 // We end font definition before blanks
2331 if (!font.equalExceptLatex(running_font) && open_font) {
2332 column += running_font.latexWriteEndChanges(os,
2334 (i == main_body-1) ? basefont : font);
2335 running_font = basefont;
2339 // Blanks are printed before start of fontswitch
2341 // Do not print the separation of the optional argument
2342 if (i != main_body - 1) {
2343 SimpleTeXBlanks(os, texrow, i,
2344 column, font, style);
2348 // Do we need to change font?
2349 if (!font.equalExceptLatex(running_font)
2350 && i != main_body-1) {
2351 column += font.latexWriteStartChanges(os, basefont,
2353 running_font = font;
2357 if (c == LyXParagraph::META_NEWLINE) {
2358 // newlines are handled differently here than
2359 // the default in SimpleTeXSpecialChars().
2360 if (!style.newline_allowed
2361 || font.latex() == LyXFont::ON) {
2365 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2368 basefont = getFont(-1);
2369 running_font = basefont;
2370 if (font.family() ==
2371 LyXFont::TYPEWRITER_FAMILY) {
2379 texrow.start(this, i + 1);
2382 SimpleTeXSpecialChars(os, texrow, moving_arg,
2383 font, running_font, basefont,
2384 open_font, style, i, column, c);
2388 // If we have an open font definition, we have to close it
2390 LyXParagraph * p = 0;
2391 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2392 && (p = NextAfterFootnote()) != 0)
2393 running_font.latexWriteEndChanges(os, basefont,
2396 running_font.latexWriteEndChanges(os, basefont, basefont);
2399 // Needed if there is an optional argument but no contents.
2400 if (main_body > 0 && main_body == size()) {
2402 return_value = false;
2405 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2406 return return_value;
2410 // This one spits out the text of a table paragraph
2411 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2413 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2415 bool return_value = false;
2417 LyXLayout const & style =
2418 textclasslist.Style(current_view->buffer()->params.textclass,
2422 if (!IsDummy()) { // it is dummy if it is in a float!!!
2423 if (style.isCommand()) {
2426 } else if (align != LYX_ALIGN_LAYOUT) {
2429 return_value = true;
2432 os << "\\noindent ";
2436 case LYX_ALIGN_NONE:
2437 case LYX_ALIGN_BLOCK:
2438 case LYX_ALIGN_LAYOUT:
2439 case LYX_ALIGN_SPECIAL: break;
2440 case LYX_ALIGN_LEFT:
2441 os << "\\raggedright ";
2444 case LYX_ALIGN_RIGHT:
2445 os << "\\raggedleft ";
2448 case LYX_ALIGN_CENTER:
2449 os << "\\centering ";
2455 LyXFont basefont = getFont(-1); // Get layout font
2456 // Which font is currently active?
2457 LyXFont running_font = basefont;
2459 // Do we have an open font change?
2460 bool open_font = false;
2461 int current_cell_number = -1;
2462 int tmp = table->TexEndOfCell(os, current_cell_number);
2463 for (; tmp > 0 ; --tmp)
2466 texrow.start(this, 0);
2468 bool is_rtl = getParLanguage()->RightToLeft;
2469 bool first_in_cell = true;
2471 for (size_type i = 0; i < size(); ++i) {
2472 char c = GetChar(i);
2473 if (table->IsContRow(current_cell_number + 1)) {
2474 if (c == LyXParagraph::META_NEWLINE)
2475 ++current_cell_number;
2480 if (first_in_cell && is_rtl) {
2483 first_in_cell = false;
2486 // Fully instantiated font
2487 LyXFont font = getFont(i);
2488 last_font = running_font;
2490 // Spaces at end of font change are simulated to be
2491 // outside font change.
2492 // i.e. we write "\textXX{text} " rather than
2493 // "\textXX{text }". (Asger)
2494 if (open_font && c == ' ' && i <= size() - 2
2495 && getFont(i + 1) != running_font
2496 && getFont(i + 1) != font) {
2497 font = getFont(i + 1);
2500 // We end font definition before blanks
2501 if (font != running_font && open_font) {
2502 column += running_font.latexWriteEndChanges(os,
2505 running_font = basefont;
2508 // Blanks are printed before start of fontswitch
2510 SimpleTeXBlanks(os, texrow, i, column, font, style);
2512 // Do we need to change font?
2513 if (font != running_font) {
2514 column += font.latexWriteStartChanges(os, basefont,
2516 running_font = font;
2519 // Do we need to turn on LaTeX mode?
2520 if (font.latex() != running_font.latex()) {
2521 if (font.latex() == LyXFont::ON
2522 && style.needprotect) {
2527 if (c == LyXParagraph::META_NEWLINE) {
2528 // special case for inside a table
2529 // different from default case in
2530 // SimpleTeXSpecialChars()
2532 column += running_font
2533 .latexWriteEndChanges(os, basefont,
2537 basefont = getFont(-1);
2538 running_font = basefont;
2539 ++current_cell_number;
2540 if (table->CellHasContRow(current_cell_number) >= 0) {
2541 TeXContTableRows(os, i + 1,
2542 current_cell_number,
2545 if (is_rtl && !first_in_cell) {
2547 first_in_cell = true;
2550 // if this cell follow only ContRows till end don't
2551 // put the EndOfCell because it is put after the
2553 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2554 --current_cell_number;
2557 int tmp = table->TexEndOfCell(os,
2558 current_cell_number);
2561 } else if (tmp < 0) {
2567 texrow.start(this, i + 1);
2569 SimpleTeXSpecialChars(os, texrow, false,
2570 font, running_font, basefont,
2571 open_font, style, i, column, c);
2575 // If we have an open font definition, we have to close it
2577 running_font.latexWriteEndChanges(os, basefont, basefont);
2579 ++current_cell_number;
2580 if (is_rtl && !first_in_cell)
2582 tmp = table->TexEndOfCell(os, current_cell_number);
2583 for (; tmp > 0; --tmp)
2585 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2586 return return_value;
2590 // This one spits out the text off ContRows in tables
2591 bool LyXParagraph::TeXContTableRows(ostream & os,
2592 LyXParagraph::size_type i,
2593 int current_cell_number,
2594 int & column, TexRow & texrow)
2596 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2602 bool return_value = false;
2603 LyXLayout const & style =
2604 textclasslist.Style(current_view->buffer()->params.textclass,
2606 LyXFont basefont = getFont(-1); // Get layout font
2608 // Which font is currently active?
2609 LyXFont running_font = basefont;
2610 // Do we have an open font change?
2611 bool open_font = false;
2613 size_type lastpos = i;
2614 int cell = table->CellHasContRow(current_cell_number);
2615 ++current_cell_number;
2617 // first find the right position
2619 for (; (i < size()) && (current_cell_number<cell); ++i) {
2621 if (c == LyXParagraph::META_NEWLINE)
2622 ++current_cell_number;
2626 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2630 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2635 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2639 // Fully instantiated font
2640 LyXFont font = getFont(i);
2641 last_font = running_font;
2643 // Spaces at end of font change are simulated to
2644 // be outside font change. i.e. we write
2645 // "\textXX{text} " rather than "\textXX{text }".
2647 if (open_font && c == ' ' && i <= size() - 2
2648 && getFont(i + 1) != running_font
2649 && getFont(i + 1) != font) {
2650 font = getFont(i + 1);
2653 // We end font definition before blanks
2654 if (font != running_font && open_font) {
2655 column += running_font.latexWriteEndChanges(os, basefont, font);
2656 running_font = basefont;
2659 // Blanks are printed before start of fontswitch
2661 SimpleTeXBlanks(os, texrow, i,
2662 column, font, style);
2664 // Do we need to change font?
2665 if (font != running_font) {
2667 font.latexWriteStartChanges(os,
2670 running_font = font;
2673 // Do we need to turn on LaTeX mode?
2674 if (font.latex() != running_font.latex()) {
2675 if (font.latex() == LyXFont::ON
2676 && style.needprotect) {
2681 SimpleTeXSpecialChars(os, texrow, false, font,
2682 running_font, basefont,
2683 open_font, style, i, column, c);
2685 // If we have an open font definition, we have to close it
2687 running_font.latexWriteEndChanges(os, basefont,
2691 basefont = getFont(-1);
2692 running_font = basefont;
2693 cell = table->CellHasContRow(current_cell_number);
2695 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2696 return return_value;
2700 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2702 bool retval = false;
2704 case LyXParagraph::META_HFILL:
2705 sgml_string.erase();
2707 case LyXParagraph::META_NEWLINE:
2711 sgml_string = "&";
2714 sgml_string = "<";
2717 sgml_string = ">";
2720 sgml_string = "$";
2723 sgml_string = "#";
2726 sgml_string = "%";
2729 sgml_string = "[";
2732 sgml_string = "]";
2735 sgml_string = "{";
2738 sgml_string = "}";
2741 sgml_string = "˜";
2744 sgml_string = """;
2747 sgml_string = "\";
2753 case '\0': // Ignore :-)
2754 sgml_string.erase();
2764 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2765 int & desc_on, int depth)
2768 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2770 LyXFont font1, font2;
2773 size_type main_body;
2774 bool emph_flag = false;
2776 LyXLayout const & style =
2777 textclasslist.Style(current_view->buffer()->params.textclass,
2780 if (style.labeltype != LABEL_MANUAL)
2783 main_body = BeginningOfMainBody();
2785 // Gets paragraph main font.
2787 font1 = style.labelfont;
2791 int char_line_count = depth;
2792 os << newlineAndDepth(depth);
2793 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2794 os << "<INFORMALTABLE>"
2795 << newlineAndDepth(++depth);
2797 int current_cell_number = -1;
2798 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2800 // Parsing main loop.
2801 for (size_type i = 0; i < size(); ++i) {
2803 if (table->IsContRow(current_cell_number+1)) {
2804 if (c == LyXParagraph::META_NEWLINE)
2805 ++current_cell_number;
2810 // Fully instantiated font
2813 // Handle <emphasis> tag.
2814 if (font1.emph() != font2.emph() && i) {
2815 if (font2.emph() == LyXFont::ON) {
2818 } else if (emph_flag) {
2819 os << "</emphasis>";
2823 if (c == LyXParagraph::META_NEWLINE) {
2824 // We have only to control for emphasis open here!
2826 os << "</emphasis>";
2829 font1 = font2 = getFont(-1);
2830 ++current_cell_number;
2831 if (table->CellHasContRow(current_cell_number) >= 0) {
2832 DocBookContTableRows(os, extra, desc_on, i + 1,
2833 current_cell_number,
2836 // if this cell follow only ContRows till end don't
2837 // put the EndOfCell because it is put after the
2839 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2840 --current_cell_number;
2843 tmp = table->DocBookEndOfCell(os,
2844 current_cell_number,
2849 } else if (c == LyXParagraph::META_INSET) {
2850 inset = GetInset(i);
2852 std::ostringstream ost;
2853 inset->DocBook(ost);
2854 string tmp_out = ost.str().c_str();
2857 inset->DocBook(ost);
2859 char * ctmp = ost.str();
2860 string tmp_out(ctmp);
2864 // This code needs some explanation:
2865 // Two insets are treated specially
2866 // label if it is the first element in a
2867 // command paragraph
2869 // graphics inside tables or figure floats
2871 // title (the equivalente in latex for this
2873 // and title should come first
2876 if(desc_on != 3 || i != 0) {
2877 if(tmp_out[0] == '@') {
2879 extra += frontStrip(tmp_out,
2882 os << frontStrip(tmp_out,
2887 } else if (font2.latex() == LyXFont::ON) {
2888 // "TeX"-Mode on == > SGML-Mode on.
2894 if (linuxDocConvertChar(c, sgml_string)
2895 && !style.free_spacing) {
2896 // in freespacing mode, spaces are
2897 // non-breaking characters
2902 << "</term><listitem><para>";
2914 // Needed if there is an optional argument but no contents.
2915 if (main_body > 0 && main_body == size()) {
2920 os << "</emphasis>";
2923 ++current_cell_number;
2924 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2925 // Resets description flag correctly.
2928 // <term> not closed...
2932 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2933 os << "</INFORMALTABLE>";
2935 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2940 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2942 LyXParagraph::size_type i,
2943 int current_cell_number, int &column)
2948 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2953 //string emph = "emphasis";
2954 bool emph_flag = false;
2955 int char_line_count = 0;
2957 LyXLayout const & style =
2958 textclasslist.Style(current_view->buffer()->params.textclass,
2961 size_type main_body;
2962 if (style.labeltype != LABEL_MANUAL)
2965 main_body = BeginningOfMainBody();
2967 // Gets paragraph main font.
2970 font1 = style.labelfont;
2974 size_type lastpos = i;
2975 int cell = table->CellHasContRow(current_cell_number);
2976 ++current_cell_number;
2978 // first find the right position
2980 for (; i < size() && current_cell_number < cell; ++i) {
2982 if (c == LyXParagraph::META_NEWLINE)
2983 ++current_cell_number;
2987 // I don't know how to handle this so I comment it
2988 // for the moment (Jug)
2989 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2990 // file += " \\\\\n";
2993 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2998 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3002 // Fully instantiated font
3005 // Handle <emphasis> tag.
3006 if (font1.emph() != font2.emph() && i) {
3007 if (font2.emph() == LyXFont::ON) {
3010 } else if (emph_flag) {
3011 os << "</emphasis>";
3015 if (c == LyXParagraph::META_INSET) {
3016 inset = GetInset(i);
3018 std::ostringstream ost;
3019 inset->DocBook(ost);
3020 string tmp_out = ost.str().c_str();
3023 inset->DocBook(ost);
3025 char * ctmp = ost.str();
3026 string tmp_out(ctmp);
3030 // This code needs some explanation:
3031 // Two insets are treated specially
3032 // label if it is the first element in a
3033 // command paragraph
3035 // graphics inside tables or figure floats
3036 // can't go on title (the equivalente in
3037 // latex for this case is caption and title
3038 // should come first
3041 if(desc_on != 3 || i != 0) {
3042 if(tmp_out[0] == '@') {
3044 extra += frontStrip(tmp_out, '@');
3046 os << frontStrip(tmp_out, '@');
3050 } else if (font2.latex() == LyXFont::ON) {
3051 // "TeX"-Mode on == > SGML-Mode on.
3057 if (linuxDocConvertChar(c, sgml_string)
3058 && !style.free_spacing) {
3059 // in freespacing mode, spaces are
3060 // non-breaking characters
3065 << "</term><listitem><para>";
3075 // we have only to control for emphasis open here!
3077 os << "</emphasis>";
3080 font1 = font2 = getFont(-1);
3081 cell = table->CellHasContRow(current_cell_number);
3083 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3087 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3088 LyXParagraph::size_type const i,
3089 int & column, LyXFont const & font,
3090 LyXLayout const & style)
3092 if (column > tex_code_break_column
3094 && GetChar(i - 1) != ' '
3096 // In LaTeX mode, we don't want to
3097 // break lines since some commands
3099 && ! (font.latex() == LyXFont::ON)
3100 // same in FreeSpacing mode
3101 && !style.free_spacing
3102 // In typewriter mode, we want to avoid
3103 // ! . ? : at the end of a line
3104 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3105 && (GetChar(i-1) == '.'
3106 || GetChar(i-1) == '?'
3107 || GetChar(i-1) == ':'
3108 || GetChar(i-1) == '!'))) {
3109 if (tex_code_break_column == 0) {
3110 // in batchmode we need LaTeX to still
3111 // see it as a space not as an extra '\n'
3117 texrow.start(this, i + 1);
3119 } else if (font.latex() == LyXFont::OFF) {
3120 if (style.free_spacing) {
3129 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3132 LyXFont & running_font,
3135 LyXLayout const & style,
3136 LyXParagraph::size_type & i,
3137 int & column, char const c)
3139 // Two major modes: LaTeX or plain
3140 // Handle here those cases common to both modes
3141 // and then split to handle the two modes separately.
3143 case LyXParagraph::META_INSET: {
3144 Inset * inset = GetInset(i);
3147 int len = os.tellp();
3148 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3149 || inset->LyxCode() == Inset::MATH_CODE
3150 || inset->LyxCode() == Inset::URL_CODE)
3151 && running_font.isRightToLeft()) {
3156 int tmp = inset->Latex(os, moving_arg,
3157 style.free_spacing);
3165 column += os.tellp() - len;
3174 case LyXParagraph::META_NEWLINE:
3176 column += running_font.latexWriteEndChanges(os,
3181 basefont = getFont(-1);
3182 running_font = basefont;
3185 case LyXParagraph::META_HFILL:
3191 // And now for the special cases within each mode
3192 // Are we in LaTeX mode?
3193 if (font.latex() == LyXFont::ON) {
3194 // at present we only have one option
3195 // but I'll leave it as a switch statement
3196 // so its simpler to extend. (ARRae)
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 os << "\\textbackslash{}";
3217 case '°': case '±': case '²': case '³':
3218 case '×': case '÷': case '¹': case 'ª':
3219 case 'º': case '¬': case 'µ':
3220 if (current_view->buffer()->params.inputenc == "latin1") {
3221 os << "\\ensuremath{"
3230 case '|': case '<': case '>':
3231 // In T1 encoding, these characters exist
3232 if (lyxrc.fontenc == "T1") {
3234 //... but we should avoid ligatures
3235 if ((c == '>' || c == '<')
3237 && GetChar(i + 1) == c){
3238 os << "\\textcompwordmark{}";
3243 // Typewriter font also has them
3244 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3248 // Otherwise, we use what LaTeX
3252 os << "\\textless{}";
3256 os << "\\textgreater{}";
3260 os << "\\textbar{}";
3266 case '-': // "--" in Typewriter mode -> "-{}-"
3268 && GetChar(i + 1) == '-'
3269 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3278 os << "\\char`\\\"{}";
3283 if (current_view->buffer()->params.inputenc == "default") {
3292 case '%': case '#': case '{':
3299 os << "\\textasciitilde{}";
3304 os << "\\textasciicircum{}";
3308 case '*': case '[': case ']':
3309 // avoid being mistaken for optional arguments
3310 os << '{' << c << '}';
3315 // Blanks are printed before font switching.
3316 // Sure? I am not! (try nice-latex)
3317 // I am sure it's correct. LyX might be smarter
3318 // in the future, but for now, nothing wrong is
3323 /* idea for labels --- begin*/
3327 && font.family() != LyXFont::TYPEWRITER_FAMILY
3328 && GetChar(i + 1) == 'y'
3329 && GetChar(i + 2) == 'X') {
3337 && font.family() != LyXFont::TYPEWRITER_FAMILY
3338 && GetChar(i + 1) == 'e'
3339 && GetChar(i + 2) == 'X') {
3344 // Check for "LaTeX2e"
3347 && font.family() != LyXFont::TYPEWRITER_FAMILY
3348 && GetChar(i + 1) == 'a'
3349 && GetChar(i + 2) == 'T'
3350 && GetChar(i + 3) == 'e'
3351 && GetChar(i + 4) == 'X'
3352 && GetChar(i + 5) == '2'
3353 && GetChar(i + 6) == 'e') {
3358 // Check for "LaTeX"
3361 && font.family() != LyXFont::TYPEWRITER_FAMILY
3362 && GetChar(i + 1) == 'a'
3363 && GetChar(i + 2) == 'T'
3364 && GetChar(i + 3) == 'e'
3365 && GetChar(i + 4) == 'X') {
3369 /* idea for labels --- end*/
3370 } else if (c != '\0') {
3381 bool LyXParagraph::RoffContTableRows(ostream & os,
3382 LyXParagraph::size_type i,
3388 LyXFont font1(LyXFont::ALL_INHERIT);
3393 string fname2 = TmpFileName(string(), "RAT2");
3395 int cell = table->CellHasContRow(actcell);
3398 // first find the right position
3400 for (; i < size() && actcell < cell; ++i) {
3402 if (c == LyXParagraph::META_NEWLINE)
3407 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3410 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3412 font2 = GetFontSettings(i);
3413 if (font1.latex() != font2.latex()) {
3414 if (font2.latex() != LyXFont::OFF)
3419 case LyXParagraph::META_INSET:
3420 if ((inset = GetInset(i))) {
3422 stringstream ss(ios::in | ios::out);
3449 case LyXParagraph::META_NEWLINE:
3451 case LyXParagraph::META_HFILL:
3460 lyxerr.debug() << "RoffAsciiTable: "
3461 "NULL char in structure."
3466 cell = table->CellHasContRow(actcell);
3473 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3475 TexRow & foot_texrow,
3478 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3479 LyXParagraph * par = this;
3482 (par->depth == depth) &&
3483 (par->footnoteflag == footnoteflag)) {
3485 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3486 if (textclasslist.Style(current_view->buffer()->params.textclass,
3487 par->layout).isEnvironment()
3488 || par->pextra_type != PEXTRA_NONE) {
3489 par = par->TeXEnvironment(os, texrow,
3493 par = par->TeXOnePar(os, texrow, false,
3498 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3504 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3506 TexRow & foot_texrow,
3509 bool eindent_open = false;
3510 bool foot_this_level = false;
3511 // flags when footnotetext should be appended to file.
3512 static bool minipage_open = false;
3513 static int minipage_open_depth = 0;
3514 char par_sep = current_view->buffer()->params.paragraph_separation;
3516 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3518 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3520 LyXLayout const & style =
3521 textclasslist.Style(current_view->buffer()->params.textclass,
3524 if (pextra_type == PEXTRA_INDENT) {
3525 if (!pextra_width.empty()) {
3526 os << "\\begin{LyXParagraphIndent}{"
3527 << pextra_width << "}\n";
3529 //float ib = atof(pextra_widthp.c_str())/100;
3530 // string can't handle floats at present (971109)
3531 // so I'll do a conversion by hand knowing that
3532 // the limits are 0.0 to 1.0. ARRae.
3533 os << "\\begin{LyXParagraphIndent}{";
3534 switch (pextra_widthp.length()) {
3546 os << "\\columnwidth}\n";
3549 eindent_open = true;
3551 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3552 if (pextra_hfill && Previous() &&
3553 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3554 os << "\\hfill{}\n";
3557 if (par_sep == BufferParams::PARSEP_INDENT) {
3558 os << "{\\setlength\\parindent{0pt}\n";
3561 os << "\\begin{minipage}";
3562 switch(pextra_alignment) {
3563 case MINIPAGE_ALIGN_TOP:
3566 case MINIPAGE_ALIGN_MIDDLE:
3569 case MINIPAGE_ALIGN_BOTTOM:
3573 if (!pextra_width.empty()) {
3574 os << '{' << pextra_width << "}\n";
3576 //float ib = atof(par->pextra_width.c_str())/100;
3577 // string can't handle floats at present
3578 // so I'll do a conversion by hand knowing that
3579 // the limits are 0.0 to 1.0. ARRae.
3581 switch (pextra_widthp.length()) {
3593 os << "\\columnwidth}\n";
3596 if (par_sep == BufferParams::PARSEP_INDENT) {
3597 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3600 minipage_open = true;
3601 minipage_open_depth = depth;
3604 #ifdef WITH_WARNINGS
3605 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3606 //I disabled it because it breaks when lists span on several
3609 if (style.isEnvironment()){
3610 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3611 #ifdef FANCY_FOOTNOTE_CODE
3612 if (foot_count < 0) {
3613 // flag that footnote[mark][text] should be
3614 // used for any footnotes from now on
3616 foot_this_level = true;
3619 os << "\\begin{" << style.latexname() << "}{"
3620 << labelwidthstring << "}\n";
3621 } else if (style.labeltype == LABEL_BIBLIO) {
3623 os << "\\begin{" << style.latexname() << "}{"
3624 << bibitemWidthest(current_view->painter())
3626 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3627 #ifdef FANCY_FOOTNOTE_CODE
3628 if (foot_count < 0) {
3629 // flag that footnote[mark][text] should be
3630 // used for any footnotes from now on
3632 foot_this_level = true;
3635 os << "\\begin{" << style.latexname() << '}'
3636 << style.latexparam() << '\n';
3638 os << "\\begin{" << style.latexname() << '}'
3639 << style.latexparam() << '\n';
3642 LyXParagraph * par = this;
3644 par = par->TeXOnePar(os, texrow, false,
3645 foot, foot_texrow, foot_count);
3647 if (minipage_open && par && !style.isEnvironment() &&
3648 (par->pextra_type == PEXTRA_MINIPAGE) &&
3649 par->pextra_start_minipage) {
3650 os << "\\end{minipage}\n";
3652 if (par_sep == BufferParams::PARSEP_INDENT) {
3656 minipage_open = false;
3658 if (par && par->depth > depth) {
3659 if (textclasslist.Style(current_view->buffer()->params.textclass,
3660 par->layout).isParagraph()
3663 // How to handle this? (Lgb)
3664 //&& !suffixIs(os, "\n\n")
3666 // There should be at least one '\n' already
3667 // but we need there to be two for Standard
3668 // paragraphs that are depth-increment'ed to be
3669 // output correctly. However, tables can
3670 // also be paragraphs so don't adjust them.
3673 // Will it ever harm to have one '\n' too
3674 // many? i.e. that we sometimes will have
3675 // three in a row. (Lgb)
3679 par = par->TeXDeeper(os, texrow,
3680 foot, foot_texrow, foot_count);
3682 if (par && par->layout == layout && par->depth == depth &&
3683 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3684 if (par->pextra_hfill && par->Previous() &&
3685 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3686 os << "\\hfill{}\n";
3689 if (par_sep == BufferParams::PARSEP_INDENT) {
3690 os << "{\\setlength\\parindent{0pt}\n";
3693 os << "\\begin{minipage}";
3694 switch(par->pextra_alignment) {
3695 case MINIPAGE_ALIGN_TOP:
3698 case MINIPAGE_ALIGN_MIDDLE:
3701 case MINIPAGE_ALIGN_BOTTOM:
3705 if (!par->pextra_width.empty()) {
3706 os << '{' << par->pextra_width << "}\n";
3708 //float ib = atof(par->pextra_widthp.c_str())/100;
3709 // string can't handle floats at present
3710 // so I'll do a conversion by hand knowing that
3711 // the limits are 0.0 to 1.0. ARRae.
3713 switch (par->pextra_widthp.length()) {
3718 os << "0." << par->pextra_widthp;
3721 os << "0.0" << par->pextra_widthp;
3723 os << "\\columnwidth}\n";
3726 if (par_sep == BufferParams::PARSEP_INDENT) {
3727 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3730 minipage_open = true;
3731 minipage_open_depth = par->depth;
3734 && par->layout == layout
3735 && par->depth == depth
3736 && par->pextra_type == pextra_type
3737 && par->footnoteflag == footnoteflag);
3739 if (style.isEnvironment()) {
3740 os << "\\end{" << style.latexname() << '}';
3741 // maybe this should go after the minipage closes?
3742 if (foot_this_level) {
3743 if (foot_count >= 1) {
3744 if (foot_count > 1) {
3745 os << "\\addtocounter{footnote}{-"
3750 texrow += foot_texrow;
3752 foot_texrow.reset();
3757 if (minipage_open && (minipage_open_depth == depth) &&
3758 (!par || par->pextra_start_minipage ||
3759 par->pextra_type != PEXTRA_MINIPAGE)) {
3760 os << "\\end{minipage}\n";
3762 if (par_sep == BufferParams::PARSEP_INDENT) {
3766 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3767 os << "\\medskip\n\n";
3771 minipage_open = false;
3774 os << "\\end{LyXParagraphIndent}\n";
3777 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3778 && par->pextra_hfill)) {
3782 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3783 return par; // ale970302
3787 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3788 ostream & foot, TexRow & foot_texrow,
3792 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3793 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3794 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3795 "No footnote!" << endl;
3797 LyXParagraph * par = this;
3798 LyXLayout const & style =
3799 textclasslist.Style(current_view->buffer()->params.textclass,
3800 previous->GetLayout());
3802 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3803 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3804 "Float other than footnote in command"
3805 " with moving argument is illegal" << endl;
3808 if (footnotekind != LyXParagraph::FOOTNOTE
3809 && footnotekind != LyXParagraph::MARGIN
3812 // How to solve this?
3813 //&& !suffixIs(file, '\n')
3815 // we need to ensure that real floats like tables and figures
3816 // have their \begin{} on a new line otherwise we can get
3817 // incorrect results when using the endfloat.sty package
3818 // especially if two floats follow one another. ARRae 981022
3819 // NOTE: if the file is length 0 it must have just been
3820 // written out so we assume it ended with a '\n'
3822 // As far as I can see there is never any harm in writing
3823 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3828 bool moving_arg = false;
3829 bool need_closing = false;
3830 bool is_rtl = isRightToLeftPar();
3832 if (is_rtl != parent_is_rtl) {
3837 need_closing = true;
3840 BufferParams * params = ¤t_view->buffer()->params;
3841 bool footer_in_body = true;
3842 switch (footnotekind) {
3843 case LyXParagraph::FOOTNOTE:
3844 if (style.intitle) {
3845 os << "\\thanks{\n";
3846 footer_in_body = false;
3849 if (foot_count == -1) {
3850 // we're at depth 0 so we can use:
3851 os << "\\footnote{%\n";
3852 footer_in_body = false;
3854 os << "\\footnotemark{}%\n";
3856 // we only need this when there are
3857 // multiple footnotes
3858 os << "\\stepcounter{footnote}";
3860 os << "\\footnotetext{%\n";
3861 foot_texrow.start(this, 0);
3862 foot_texrow.newline();
3867 case LyXParagraph::MARGIN:
3868 os << "\\marginpar{\n";
3870 case LyXParagraph::FIG:
3871 if (pextra_type == PEXTRA_FLOATFLT
3872 && (!pextra_width.empty()
3873 || !pextra_widthp.empty())) {
3874 if (!pextra_width.empty())
3875 os << "\\begin{floatingfigure}{"
3876 << pextra_width << "}\n";
3878 os << "\\begin{floatingfigure}{"
3879 << atoi(pextra_widthp.c_str())/100.0
3880 << "\\textwidth}\n";
3882 os << "\\begin{figure}";
3883 if (!params->float_placement.empty()) {
3884 os << '[' << params->float_placement << "]\n";
3890 case LyXParagraph::TAB:
3891 os << "\\begin{table}";
3892 if (!params->float_placement.empty()) {
3893 os << '[' << params->float_placement << "]\n";
3898 case LyXParagraph::WIDE_FIG:
3899 os << "\\begin{figure*}";
3900 if (!params->float_placement.empty()) {
3901 os << '[' << params->float_placement << "]\n";
3906 case LyXParagraph::WIDE_TAB:
3907 os << "\\begin{table*}";
3908 if (!params->float_placement.empty()) {
3909 os << '[' << params->float_placement << "]\n";
3914 case LyXParagraph::ALGORITHM:
3915 os << "\\begin{algorithm}\n";
3920 if (footnotekind != LyXParagraph::FOOTNOTE
3921 || !footer_in_body) {
3922 // Process text for all floats except footnotes in body
3924 LyXLayout const & style =
3926 .Style(current_view->buffer()->params
3930 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3932 if (style.isEnvironment()
3933 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3934 // Allows the use of minipages within float
3935 // environments. Shouldn't be circular because
3936 // we don't support footnotes inside
3937 // floats (yet). ARRae
3938 par = par->TeXEnvironment(os, texrow,
3942 par = par->TeXOnePar(os, texrow, moving_arg,
3947 if (par && !par->IsDummy() && par->depth > depth) {
3948 par = par->TeXDeeper(os, texrow,
3952 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3954 // process footnotes > depth 0 or in environments separately
3955 // NOTE: Currently don't support footnotes within footnotes
3956 // even though that is possible using the \footnotemark
3958 std::ostringstream dummy;
3962 TexRow dummy_texrow;
3963 int dummy_count = 0;
3965 LyXLayout const & style =
3967 .Style(current_view->buffer()->params
3971 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3973 if (style.isEnvironment()
3974 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3975 // Allows the use of minipages within float
3976 // environments. Shouldn't be circular because
3977 // we don't support footnotes inside
3978 // floats (yet). ARRae
3979 par = par->TeXEnvironment(foot, foot_texrow,
3980 dummy, dummy_texrow,
3983 par = par->TeXOnePar(foot, foot_texrow,
3985 dummy, dummy_texrow,
3989 if (par && !par->IsDummy() && par->depth > depth) {
3990 par = par->TeXDeeper(foot, foot_texrow,
3991 dummy, dummy_texrow,
3995 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3997 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3998 "Footnote in a Footnote -- not supported"
4001 #ifndef HAVE_OSTREAM
4002 delete [] dummy.str();
4006 switch (footnotekind) {
4007 case LyXParagraph::FOOTNOTE:
4008 if (footer_in_body) {
4009 // This helps tell which of the multiple
4010 // footnotetexts an error was in.
4012 foot_texrow.newline();
4017 case LyXParagraph::MARGIN:
4020 case LyXParagraph::FIG:
4021 if (pextra_type == PEXTRA_FLOATFLT
4022 && (!pextra_width.empty()
4023 || !pextra_widthp.empty()))
4024 os << "\\end{floatingfigure}";
4026 os << "\\end{figure}";
4028 case LyXParagraph::TAB:
4029 os << "\\end{table}";
4031 case LyXParagraph::WIDE_FIG:
4032 os << "\\end{figure*}";
4034 case LyXParagraph::WIDE_TAB:
4035 os << "\\end{table*}";
4037 case LyXParagraph::ALGORITHM:
4038 os << "\\end{algorithm}";
4045 if (footnotekind != LyXParagraph::FOOTNOTE
4046 && footnotekind != LyXParagraph::MARGIN) {
4047 // we need to ensure that real floats like tables and figures
4048 // have their \end{} on a line of their own otherwise we can
4049 // get incorrect results when using the endfloat.sty package.
4054 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4059 bool LyXParagraph::IsDummy() const
4061 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4062 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4066 void LyXParagraph::SetPExtraType(int type, char const * width,
4067 char const * widthp)
4070 pextra_width = width;
4071 pextra_widthp = widthp;
4073 if (textclasslist.Style(current_view->buffer()->params.textclass,
4074 layout).isEnvironment()) {
4079 while (par && (par->layout == layout)
4080 && (par->depth == depth)) {
4082 par = par->Previous();
4084 par = par->FirstPhysicalPar();
4085 while (par && par->depth > depth) {
4086 par = par->Previous();
4088 par = par->FirstPhysicalPar();
4092 while (par && (par->layout == layout)
4093 && (par->depth == depth)) {
4094 par->pextra_type = type;
4095 par->pextra_width = width;
4096 par->pextra_widthp = widthp;
4097 par = par->NextAfterFootnote();
4098 if (par && (par->depth > depth))
4099 par->SetPExtraType(type, width, widthp);
4100 while (par && ((par->depth > depth) || par->IsDummy()))
4101 par = par->NextAfterFootnote();
4107 void LyXParagraph::UnsetPExtraType()
4109 if (pextra_type == PEXTRA_NONE)
4112 pextra_type = PEXTRA_NONE;
4113 pextra_width.erase();
4114 pextra_widthp.erase();
4116 if (textclasslist.Style(current_view->buffer()->params.textclass,
4117 layout).isEnvironment()) {
4122 while (par && (par->layout == layout)
4123 && (par->depth == depth)) {
4125 par = par->Previous();
4127 par = par->FirstPhysicalPar();
4128 while (par && par->depth > depth) {
4129 par = par->Previous();
4131 par = par->FirstPhysicalPar();
4135 while (par && (par->layout == layout)
4136 && (par->depth == depth)) {
4137 par->pextra_type = PEXTRA_NONE;
4138 par->pextra_width.erase();
4139 par->pextra_widthp.erase();
4140 par = par->NextAfterFootnote();
4141 if (par && (par->depth > depth))
4142 par->UnsetPExtraType();
4143 while (par && ((par->depth > depth) || par->IsDummy()))
4144 par = par->NextAfterFootnote();
4150 bool LyXParagraph::IsHfill(size_type pos) const
4152 return IsHfillChar(GetChar(pos));
4156 bool LyXParagraph::IsInset(size_type pos) const
4158 return IsInsetChar(GetChar(pos));
4162 bool LyXParagraph::IsFloat(size_type pos) const
4164 return IsFloatChar(GetChar(pos));
4168 bool LyXParagraph::IsNewline(size_type pos) const
4170 return pos >= 0 && IsNewlineChar(GetChar(pos));
4174 bool LyXParagraph::IsSeparator(size_type pos) const
4176 return IsSeparatorChar(GetChar(pos));
4180 bool LyXParagraph::IsLineSeparator(size_type pos) const
4182 return IsLineSeparatorChar(GetChar(pos));
4186 bool LyXParagraph::IsKomma(size_type pos) const
4188 return IsKommaChar(GetChar(pos));
4192 /// Used by the spellchecker
4193 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4195 unsigned char c = GetChar(pos);
4196 if (IsLetterChar(c))
4198 // '\0' is not a letter, allthough every string contains "" (below)
4201 // We want to pass the ' and escape chars to ispell
4202 string extra = lyxrc.isp_esc_chars + '\'';
4206 return contains(extra, ch);
4210 bool LyXParagraph::IsWord(size_type pos ) const
4212 return IsWordChar(GetChar(pos)) ;
4216 Language const * LyXParagraph::getParLanguage() const
4220 return FirstPhysicalPar()->GetFirstFontSettings()
4223 for (size_type pos = 0; pos < size(); ++pos)
4225 return GetFontSettings(pos).language();
4226 return GetFirstFontSettings().language();
4229 return previous->getParLanguage();
4231 return current_view->buffer()->params.language_info;
4235 bool LyXParagraph::isRightToLeftPar() const
4237 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4241 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4243 for(size_type i = 0; i < size(); ++i) {
4244 LyXFont font = GetFontSettings(i);
4245 if (font.language() == from) {
4246 font.setLanguage(to);
4253 bool LyXParagraph::isMultiLingual()
4255 Language const * doc_language =
4256 current_view->buffer()->params.language_info;
4257 for(size_type i = 0; i < size(); ++i) {
4258 LyXFont font = GetFontSettings(i);
4259 if (font.language() != doc_language)