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 LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
1935 InsetList::iterator it = lower_bound(insetlist.begin(),
1938 return inset_iterator(it);
1942 // returns -1 if inset not found
1943 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1946 // We could use lower_bound here too, we just need to add
1947 // the approp. operator() to matchIT (and change the name
1948 // of that struct). Code would then be:
1949 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1951 // inset, matchIT());
1952 // if ((*cit).inset == inset) {
1953 // return (*cit).pos;
1955 for (InsetList::const_iterator cit = insetlist.begin();
1956 cit != insetlist.end(); ++cit) {
1957 if ((*cit).inset == inset) {
1961 // Think about footnotes.
1962 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1963 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1965 NextAfterFootnote()->GetPositionOfInset(inset);
1967 return text.size() + 1 + further;
1973 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1976 TexRow & foot_texrow,
1979 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1980 LyXLayout const & style =
1981 textclasslist.Style(current_view->buffer()->params.textclass,
1984 bool further_blank_line = false;
1986 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1988 if (start_of_appendix) {
1989 os << "\\appendix\n";
1993 if (!spacing.isDefault()
1994 && (!Previous() || !Previous()->HasSameLayout(this))) {
1995 os << spacing.writeEnvirBegin() << "\n";
1999 if (tex_code_break_column && style.isCommand()){
2004 if (pagebreak_top) {
2006 further_blank_line = true;
2008 if (added_space_top.kind() != VSpace::NONE) {
2009 os << added_space_top.asLatexCommand(current_view->buffer()->params);
2010 further_blank_line = true;
2014 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2015 << "\\vspace{-1\\parskip}";
2016 further_blank_line = true;
2019 if (further_blank_line){
2024 Language const * language = getParLanguage();
2025 Language const * doc_language = current_view->buffer()->params.language_info;
2026 if (language != doc_language) {
2027 os << subst(lyxrc.language_command_begin, "$$lang",
2033 switch (style.latextype) {
2036 << style.latexname()
2037 << style.latexparam();
2039 case LATEX_ITEM_ENVIRONMENT:
2041 bibkey->Latex(os, false, false);
2045 case LATEX_LIST_ENVIRONMENT:
2052 bool need_par = SimpleTeXOnePar(os, texrow, moving_arg);
2054 // Spit out footnotes
2055 LyXParagraph * par = next;
2056 if (lyxrc.rtl_support) {
2057 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2058 && next->footnoteflag != footnoteflag) {
2059 LyXParagraph * p = 0;
2060 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2061 if ( (p = NextAfterFootnote()) != 0 &&
2062 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2063 is_rtl = GetFontSettings(0).isRightToLeft();
2065 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2066 par->footnoteflag != footnoteflag) {
2067 par = par->TeXFootnote(os, texrow, foot,
2068 foot_texrow, foot_count,
2070 par->SimpleTeXOnePar(os, texrow, moving_arg);
2071 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2073 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2074 (p = par->NextAfterFootnote()) != 0 &&
2075 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2076 is_rtl = GetFontSettings(0).isRightToLeft();
2081 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2082 && par->footnoteflag != footnoteflag) {
2083 par = par->TeXFootnote(os, texrow,
2084 foot, foot_texrow, foot_count,
2086 par->SimpleTeXOnePar(os, texrow, moving_arg);
2091 // Make sure that \\par is done with the font of the last
2092 // character if this has another size as the default.
2093 // This is necessary because LaTeX (and LyX on the screen)
2094 // calculates the space between the baselines according
2095 // to this font. (Matthias)
2096 LyXFont font = getFont(Last() - 1);
2098 if (style.resfont.size() != font.size()) {
2104 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2105 GetLayout()).isCommand()){
2106 if (style.resfont.size() != font.size()) {
2112 } else if (style.resfont.size() != font.size()){
2113 os << "{\\" << font.latexSize() << " \\par}";
2116 if (language != doc_language) {
2118 << subst(lyxrc.language_command_end, "$$lang",
2119 doc_language->lang);
2122 switch (style.latextype) {
2123 case LATEX_ITEM_ENVIRONMENT:
2124 case LATEX_LIST_ENVIRONMENT:
2125 if (par && (depth < par->depth)) {
2130 case LATEX_ENVIRONMENT:
2131 // if its the last paragraph of the current environment
2132 // skip it otherwise fall through
2134 && (par->layout != layout
2135 || par->depth != depth
2136 || par->pextra_type != pextra_type))
2139 // we don't need it for the last paragraph!!!
2140 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2141 && footnotekind != LyXParagraph::FOOTNOTE
2142 && footnotekind != LyXParagraph::MARGIN
2146 // don't insert this if we would be adding it
2147 // before or after a table in a float. This
2148 // little trick is needed in order to allow
2149 // use of tables in \subfigures or \subtables.
2155 further_blank_line = false;
2157 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2158 further_blank_line = true;
2161 if (added_space_bottom.kind() != VSpace::NONE) {
2162 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2163 further_blank_line = true;
2166 if (pagebreak_bottom) {
2168 further_blank_line = true;
2171 if (further_blank_line){
2176 if (!spacing.isDefault()
2177 && (!par || !par->HasSameLayout(this))) {
2178 os << spacing.writeEnvirEnd() << "\n";
2182 // we don't need it for the last paragraph!!!
2183 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2184 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2189 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2194 // This one spits out the text of the paragraph
2195 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow,
2198 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2201 return SimpleTeXOneTablePar(os, texrow);
2203 bool return_value = false;
2205 LyXLayout const & style =
2206 textclasslist.Style(current_view->buffer()->params.textclass,
2208 LyXFont basefont, last_font;
2210 // Maybe we have to create a optional argument.
2211 size_type main_body;
2212 if (style.labeltype != LABEL_MANUAL)
2215 main_body = BeginningOfMainBody();
2217 if (main_body > 0) {
2219 basefont = getFont(-2); // Get label font
2221 basefont = getFont(-1); // Get layout font
2229 if (style.isCommand()) {
2232 } else if (align != LYX_ALIGN_LAYOUT) {
2235 return_value = true;
2239 moving_arg |= style.needprotect;
2241 // Which font is currently active?
2242 LyXFont running_font(basefont);
2243 // Do we have an open font change?
2244 bool open_font = false;
2246 texrow.start(this, 0);
2248 for (size_type i = 0; i < size(); ++i) {
2250 // First char in paragraph or after label?
2251 if (i == main_body && !IsDummy()) {
2252 if (main_body > 0) {
2254 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2257 basefont = getFont(-1); // Now use the layout font
2258 running_font = basefont;
2262 if (style.isCommand()) {
2265 } else if (align != LYX_ALIGN_LAYOUT) {
2268 return_value = true;
2272 os << "\\noindent ";
2276 case LYX_ALIGN_NONE:
2277 case LYX_ALIGN_BLOCK:
2278 case LYX_ALIGN_LAYOUT:
2279 case LYX_ALIGN_SPECIAL:
2281 case LYX_ALIGN_LEFT:
2282 if (getParLanguage()->lang != "hebrew") {
2283 os << "\\raggedright ";
2286 os << "\\raggedleft ";
2290 case LYX_ALIGN_RIGHT:
2291 if (getParLanguage()->lang != "hebrew") {
2292 os << "\\raggedleft ";
2295 os << "\\raggedright ";
2299 case LYX_ALIGN_CENTER:
2300 os << "\\centering ";
2308 // Fully instantiated font
2309 LyXFont font = getFont(i);
2310 LyXParagraph * p = 0;
2311 if (i == 0 && previous &&
2312 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2313 (p = PreviousBeforeFootnote()) != 0)
2314 last_font = p->getFont(p->size()-1);
2316 last_font = running_font;
2318 // Spaces at end of font change are simulated to be
2319 // outside font change, i.e. we write "\textXX{text} "
2320 // rather than "\textXX{text }". (Asger)
2321 if (open_font && c == ' ' && i <= size() - 2
2322 && !getFont(i+1).equalExceptLatex(running_font)
2323 && !getFont(i+1).equalExceptLatex(font)) {
2324 font = getFont(i + 1);
2326 // We end font definition before blanks
2327 if (!font.equalExceptLatex(running_font) && open_font) {
2328 column += running_font.latexWriteEndChanges(os,
2330 (i == main_body-1) ? basefont : font);
2331 running_font = basefont;
2335 // Blanks are printed before start of fontswitch
2337 // Do not print the separation of the optional argument
2338 if (i != main_body - 1) {
2339 SimpleTeXBlanks(os, texrow, i,
2340 column, font, style);
2344 // Do we need to change font?
2345 if (!font.equalExceptLatex(running_font)
2346 && i != main_body-1) {
2347 column += font.latexWriteStartChanges(os, basefont,
2349 running_font = font;
2353 if (c == LyXParagraph::META_NEWLINE) {
2354 // newlines are handled differently here than
2355 // the default in SimpleTeXSpecialChars().
2356 if (!style.newline_allowed
2357 || font.latex() == LyXFont::ON) {
2361 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2364 basefont = getFont(-1);
2365 running_font = basefont;
2366 if (font.family() ==
2367 LyXFont::TYPEWRITER_FAMILY) {
2375 texrow.start(this, i + 1);
2378 SimpleTeXSpecialChars(os, texrow, moving_arg,
2379 font, running_font, basefont,
2380 open_font, style, i, column, c);
2384 // If we have an open font definition, we have to close it
2386 LyXParagraph * p = 0;
2387 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2388 && (p = NextAfterFootnote()) != 0)
2389 running_font.latexWriteEndChanges(os, basefont,
2392 running_font.latexWriteEndChanges(os, basefont, basefont);
2395 // Needed if there is an optional argument but no contents.
2396 if (main_body > 0 && main_body == size()) {
2398 return_value = false;
2401 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2402 return return_value;
2406 // This one spits out the text of a table paragraph
2407 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2409 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2411 bool return_value = false;
2413 LyXLayout const & style =
2414 textclasslist.Style(current_view->buffer()->params.textclass,
2418 if (!IsDummy()) { // it is dummy if it is in a float!!!
2419 if (style.isCommand()) {
2422 } else if (align != LYX_ALIGN_LAYOUT) {
2425 return_value = true;
2428 os << "\\noindent ";
2432 case LYX_ALIGN_NONE:
2433 case LYX_ALIGN_BLOCK:
2434 case LYX_ALIGN_LAYOUT:
2435 case LYX_ALIGN_SPECIAL: break;
2436 case LYX_ALIGN_LEFT:
2437 os << "\\raggedright ";
2440 case LYX_ALIGN_RIGHT:
2441 os << "\\raggedleft ";
2444 case LYX_ALIGN_CENTER:
2445 os << "\\centering ";
2451 LyXFont basefont = getFont(-1); // Get layout font
2452 // Which font is currently active?
2453 LyXFont running_font = basefont;
2455 // Do we have an open font change?
2456 bool open_font = false;
2457 int current_cell_number = -1;
2458 int tmp = table->TexEndOfCell(os, current_cell_number);
2459 for (; tmp > 0 ; --tmp)
2462 texrow.start(this, 0);
2464 bool is_rtl = getParLanguage()->RightToLeft;
2465 bool first_in_cell = true;
2467 for (size_type i = 0; i < size(); ++i) {
2468 char c = GetChar(i);
2469 if (table->IsContRow(current_cell_number + 1)) {
2470 if (c == LyXParagraph::META_NEWLINE)
2471 ++current_cell_number;
2476 if (first_in_cell && is_rtl) {
2479 first_in_cell = false;
2482 // Fully instantiated font
2483 LyXFont font = getFont(i);
2484 last_font = running_font;
2486 // Spaces at end of font change are simulated to be
2487 // outside font change.
2488 // i.e. we write "\textXX{text} " rather than
2489 // "\textXX{text }". (Asger)
2490 if (open_font && c == ' ' && i <= size() - 2
2491 && getFont(i + 1) != running_font
2492 && getFont(i + 1) != font) {
2493 font = getFont(i + 1);
2496 // We end font definition before blanks
2497 if (font != running_font && open_font) {
2498 column += running_font.latexWriteEndChanges(os,
2501 running_font = basefont;
2504 // Blanks are printed before start of fontswitch
2506 SimpleTeXBlanks(os, texrow, i, column, font, style);
2508 // Do we need to change font?
2509 if (font != running_font) {
2510 column += font.latexWriteStartChanges(os, basefont,
2512 running_font = font;
2515 // Do we need to turn on LaTeX mode?
2516 if (font.latex() != running_font.latex()) {
2517 if (font.latex() == LyXFont::ON
2518 && style.needprotect) {
2523 if (c == LyXParagraph::META_NEWLINE) {
2524 // special case for inside a table
2525 // different from default case in
2526 // SimpleTeXSpecialChars()
2528 column += running_font
2529 .latexWriteEndChanges(os, basefont,
2533 basefont = getFont(-1);
2534 running_font = basefont;
2535 ++current_cell_number;
2536 if (table->CellHasContRow(current_cell_number) >= 0) {
2537 TeXContTableRows(os, i + 1,
2538 current_cell_number,
2541 if (is_rtl && !first_in_cell) {
2543 first_in_cell = true;
2546 // if this cell follow only ContRows till end don't
2547 // put the EndOfCell because it is put after the
2549 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2550 --current_cell_number;
2553 int tmp = table->TexEndOfCell(os,
2554 current_cell_number);
2557 } else if (tmp < 0) {
2563 texrow.start(this, i + 1);
2565 SimpleTeXSpecialChars(os, texrow, false,
2566 font, running_font, basefont,
2567 open_font, style, i, column, c);
2571 // If we have an open font definition, we have to close it
2573 running_font.latexWriteEndChanges(os, basefont, basefont);
2575 ++current_cell_number;
2576 if (is_rtl && !first_in_cell)
2578 tmp = table->TexEndOfCell(os, current_cell_number);
2579 for (; tmp > 0; --tmp)
2581 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2582 return return_value;
2586 // This one spits out the text off ContRows in tables
2587 bool LyXParagraph::TeXContTableRows(ostream & os,
2588 LyXParagraph::size_type i,
2589 int current_cell_number,
2590 int & column, TexRow & texrow)
2592 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2598 bool return_value = false;
2599 LyXLayout const & style =
2600 textclasslist.Style(current_view->buffer()->params.textclass,
2602 LyXFont basefont = getFont(-1); // Get layout font
2604 // Which font is currently active?
2605 LyXFont running_font = basefont;
2606 // Do we have an open font change?
2607 bool open_font = false;
2609 size_type lastpos = i;
2610 int cell = table->CellHasContRow(current_cell_number);
2611 ++current_cell_number;
2613 // first find the right position
2615 for (; (i < size()) && (current_cell_number<cell); ++i) {
2617 if (c == LyXParagraph::META_NEWLINE)
2618 ++current_cell_number;
2622 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2626 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2631 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2635 // Fully instantiated font
2636 LyXFont font = getFont(i);
2637 last_font = running_font;
2639 // Spaces at end of font change are simulated to
2640 // be outside font change. i.e. we write
2641 // "\textXX{text} " rather than "\textXX{text }".
2643 if (open_font && c == ' ' && i <= size() - 2
2644 && getFont(i + 1) != running_font
2645 && getFont(i + 1) != font) {
2646 font = getFont(i + 1);
2649 // We end font definition before blanks
2650 if (font != running_font && open_font) {
2651 column += running_font.latexWriteEndChanges(os, basefont, font);
2652 running_font = basefont;
2655 // Blanks are printed before start of fontswitch
2657 SimpleTeXBlanks(os, texrow, i,
2658 column, font, style);
2660 // Do we need to change font?
2661 if (font != running_font) {
2663 font.latexWriteStartChanges(os,
2666 running_font = font;
2669 // Do we need to turn on LaTeX mode?
2670 if (font.latex() != running_font.latex()) {
2671 if (font.latex() == LyXFont::ON
2672 && style.needprotect) {
2677 SimpleTeXSpecialChars(os, texrow, false, font,
2678 running_font, basefont,
2679 open_font, style, i, column, c);
2681 // If we have an open font definition, we have to close it
2683 running_font.latexWriteEndChanges(os, basefont,
2687 basefont = getFont(-1);
2688 running_font = basefont;
2689 cell = table->CellHasContRow(current_cell_number);
2691 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2692 return return_value;
2696 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2698 bool retval = false;
2700 case LyXParagraph::META_HFILL:
2701 sgml_string.erase();
2703 case LyXParagraph::META_NEWLINE:
2707 sgml_string = "&";
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 = "\";
2749 case '\0': // Ignore :-)
2750 sgml_string.erase();
2760 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2761 int & desc_on, int depth)
2764 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2766 LyXFont font1, font2;
2769 size_type main_body;
2770 bool emph_flag = false;
2772 LyXLayout const & style =
2773 textclasslist.Style(current_view->buffer()->params.textclass,
2776 if (style.labeltype != LABEL_MANUAL)
2779 main_body = BeginningOfMainBody();
2781 // Gets paragraph main font.
2783 font1 = style.labelfont;
2787 int char_line_count = depth;
2788 os << newlineAndDepth(depth);
2789 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2790 os << "<INFORMALTABLE>"
2791 << newlineAndDepth(++depth);
2793 int current_cell_number = -1;
2794 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2796 // Parsing main loop.
2797 for (size_type i = 0; i < size(); ++i) {
2799 if (table->IsContRow(current_cell_number+1)) {
2800 if (c == LyXParagraph::META_NEWLINE)
2801 ++current_cell_number;
2806 // Fully instantiated font
2809 // Handle <emphasis> tag.
2810 if (font1.emph() != font2.emph() && i) {
2811 if (font2.emph() == LyXFont::ON) {
2814 } else if (emph_flag) {
2815 os << "</emphasis>";
2819 if (c == LyXParagraph::META_NEWLINE) {
2820 // We have only to control for emphasis open here!
2822 os << "</emphasis>";
2825 font1 = font2 = getFont(-1);
2826 ++current_cell_number;
2827 if (table->CellHasContRow(current_cell_number) >= 0) {
2828 DocBookContTableRows(os, extra, desc_on, i + 1,
2829 current_cell_number,
2832 // if this cell follow only ContRows till end don't
2833 // put the EndOfCell because it is put after the
2835 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2836 --current_cell_number;
2839 tmp = table->DocBookEndOfCell(os,
2840 current_cell_number,
2845 } else if (c == LyXParagraph::META_INSET) {
2846 inset = GetInset(i);
2848 std::ostringstream ost;
2849 inset->DocBook(ost);
2850 string tmp_out = ost.str().c_str();
2853 inset->DocBook(ost);
2855 char * ctmp = ost.str();
2856 string tmp_out(ctmp);
2860 // This code needs some explanation:
2861 // Two insets are treated specially
2862 // label if it is the first element in a
2863 // command paragraph
2865 // graphics inside tables or figure floats
2867 // title (the equivalente in latex for this
2869 // and title should come first
2872 if(desc_on != 3 || i != 0) {
2873 if(tmp_out[0] == '@') {
2875 extra += frontStrip(tmp_out,
2878 os << frontStrip(tmp_out,
2883 } else if (font2.latex() == LyXFont::ON) {
2884 // "TeX"-Mode on == > SGML-Mode on.
2890 if (linuxDocConvertChar(c, sgml_string)
2891 && !style.free_spacing) {
2892 // in freespacing mode, spaces are
2893 // non-breaking characters
2898 << "</term><listitem><para>";
2910 // Needed if there is an optional argument but no contents.
2911 if (main_body > 0 && main_body == size()) {
2916 os << "</emphasis>";
2919 ++current_cell_number;
2920 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2921 // Resets description flag correctly.
2924 // <term> not closed...
2928 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2929 os << "</INFORMALTABLE>";
2931 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2936 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2938 LyXParagraph::size_type i,
2939 int current_cell_number, int &column)
2944 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2949 //string emph = "emphasis";
2950 bool emph_flag = false;
2951 int char_line_count = 0;
2953 LyXLayout const & style =
2954 textclasslist.Style(current_view->buffer()->params.textclass,
2957 size_type main_body;
2958 if (style.labeltype != LABEL_MANUAL)
2961 main_body = BeginningOfMainBody();
2963 // Gets paragraph main font.
2966 font1 = style.labelfont;
2970 size_type lastpos = i;
2971 int cell = table->CellHasContRow(current_cell_number);
2972 ++current_cell_number;
2974 // first find the right position
2976 for (; i < size() && current_cell_number < cell; ++i) {
2978 if (c == LyXParagraph::META_NEWLINE)
2979 ++current_cell_number;
2983 // I don't know how to handle this so I comment it
2984 // for the moment (Jug)
2985 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2986 // file += " \\\\\n";
2989 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2994 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2998 // Fully instantiated font
3001 // Handle <emphasis> tag.
3002 if (font1.emph() != font2.emph() && i) {
3003 if (font2.emph() == LyXFont::ON) {
3006 } else if (emph_flag) {
3007 os << "</emphasis>";
3011 if (c == LyXParagraph::META_INSET) {
3012 inset = GetInset(i);
3014 std::ostringstream ost;
3015 inset->DocBook(ost);
3016 string tmp_out = ost.str().c_str();
3019 inset->DocBook(ost);
3021 char * ctmp = ost.str();
3022 string tmp_out(ctmp);
3026 // This code needs some explanation:
3027 // Two insets are treated specially
3028 // label if it is the first element in a
3029 // command paragraph
3031 // graphics inside tables or figure floats
3032 // can't go on title (the equivalente in
3033 // latex for this case is caption and title
3034 // should come first
3037 if(desc_on != 3 || i != 0) {
3038 if(tmp_out[0] == '@') {
3040 extra += frontStrip(tmp_out, '@');
3042 os << frontStrip(tmp_out, '@');
3046 } else if (font2.latex() == LyXFont::ON) {
3047 // "TeX"-Mode on == > SGML-Mode on.
3053 if (linuxDocConvertChar(c, sgml_string)
3054 && !style.free_spacing) {
3055 // in freespacing mode, spaces are
3056 // non-breaking characters
3061 << "</term><listitem><para>";
3071 // we have only to control for emphasis open here!
3073 os << "</emphasis>";
3076 font1 = font2 = getFont(-1);
3077 cell = table->CellHasContRow(current_cell_number);
3079 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3083 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3084 LyXParagraph::size_type const i,
3085 int & column, LyXFont const & font,
3086 LyXLayout const & style)
3088 if (column > tex_code_break_column
3090 && GetChar(i - 1) != ' '
3092 // In LaTeX mode, we don't want to
3093 // break lines since some commands
3095 && ! (font.latex() == LyXFont::ON)
3096 // same in FreeSpacing mode
3097 && !style.free_spacing
3098 // In typewriter mode, we want to avoid
3099 // ! . ? : at the end of a line
3100 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3101 && (GetChar(i-1) == '.'
3102 || GetChar(i-1) == '?'
3103 || GetChar(i-1) == ':'
3104 || GetChar(i-1) == '!'))) {
3105 if (tex_code_break_column == 0) {
3106 // in batchmode we need LaTeX to still
3107 // see it as a space not as an extra '\n'
3113 texrow.start(this, i + 1);
3115 } else if (font.latex() == LyXFont::OFF) {
3116 if (style.free_spacing) {
3125 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3128 LyXFont & running_font,
3131 LyXLayout const & style,
3132 LyXParagraph::size_type & i,
3133 int & column, char const c)
3135 // Two major modes: LaTeX or plain
3136 // Handle here those cases common to both modes
3137 // and then split to handle the two modes separately.
3139 case LyXParagraph::META_INSET: {
3140 Inset * inset = GetInset(i);
3143 int len = os.tellp();
3144 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3145 || inset->LyxCode() == Inset::MATH_CODE
3146 || inset->LyxCode() == Inset::URL_CODE)
3147 && running_font.isRightToLeft()) {
3152 int tmp = inset->Latex(os, moving_arg,
3153 style.free_spacing);
3161 column += os.tellp() - len;
3170 case LyXParagraph::META_NEWLINE:
3172 column += running_font.latexWriteEndChanges(os,
3177 basefont = getFont(-1);
3178 running_font = basefont;
3181 case LyXParagraph::META_HFILL:
3187 // And now for the special cases within each mode
3188 // Are we in LaTeX mode?
3189 if (font.latex() == LyXFont::ON) {
3190 // at present we only have one option
3191 // but I'll leave it as a switch statement
3192 // so its simpler to extend. (ARRae)
3195 // make sure that we will not print
3196 // error generating chars to the tex
3197 // file. This test would not be needed
3198 // if it were done in the buffer
3206 // Plain mode (i.e. not LaTeX)
3209 os << "\\textbackslash{}";
3213 case '°': case '±': case '²': case '³':
3214 case '×': case '÷': case '¹': case 'ª':
3215 case 'º': case '¬': case 'µ':
3216 if (current_view->buffer()->params.inputenc == "latin1") {
3217 os << "\\ensuremath{"
3226 case '|': case '<': case '>':
3227 // In T1 encoding, these characters exist
3228 if (lyxrc.fontenc == "T1") {
3230 //... but we should avoid ligatures
3231 if ((c == '>' || c == '<')
3233 && GetChar(i + 1) == c){
3234 os << "\\textcompwordmark{}";
3239 // Typewriter font also has them
3240 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3244 // Otherwise, we use what LaTeX
3248 os << "\\textless{}";
3252 os << "\\textgreater{}";
3256 os << "\\textbar{}";
3262 case '-': // "--" in Typewriter mode -> "-{}-"
3264 && GetChar(i + 1) == '-'
3265 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3274 os << "\\char`\\\"{}";
3279 if (current_view->buffer()->params.inputenc == "default") {
3288 case '%': case '#': case '{':
3295 os << "\\textasciitilde{}";
3300 os << "\\textasciicircum{}";
3304 case '*': case '[': case ']':
3305 // avoid being mistaken for optional arguments
3306 os << '{' << c << '}';
3311 // Blanks are printed before font switching.
3312 // Sure? I am not! (try nice-latex)
3313 // I am sure it's correct. LyX might be smarter
3314 // in the future, but for now, nothing wrong is
3319 /* idea for labels --- begin*/
3323 && font.family() != LyXFont::TYPEWRITER_FAMILY
3324 && GetChar(i + 1) == 'y'
3325 && GetChar(i + 2) == 'X') {
3333 && font.family() != LyXFont::TYPEWRITER_FAMILY
3334 && GetChar(i + 1) == 'e'
3335 && GetChar(i + 2) == 'X') {
3340 // Check for "LaTeX2e"
3343 && font.family() != LyXFont::TYPEWRITER_FAMILY
3344 && GetChar(i + 1) == 'a'
3345 && GetChar(i + 2) == 'T'
3346 && GetChar(i + 3) == 'e'
3347 && GetChar(i + 4) == 'X'
3348 && GetChar(i + 5) == '2'
3349 && GetChar(i + 6) == 'e') {
3354 // Check for "LaTeX"
3357 && font.family() != LyXFont::TYPEWRITER_FAMILY
3358 && GetChar(i + 1) == 'a'
3359 && GetChar(i + 2) == 'T'
3360 && GetChar(i + 3) == 'e'
3361 && GetChar(i + 4) == 'X') {
3365 /* idea for labels --- end*/
3366 } else if (c != '\0') {
3377 bool LyXParagraph::RoffContTableRows(ostream & os,
3378 LyXParagraph::size_type i,
3384 LyXFont font1(LyXFont::ALL_INHERIT);
3389 string fname2 = TmpFileName(string(), "RAT2");
3391 int cell = table->CellHasContRow(actcell);
3394 // first find the right position
3396 for (; i < size() && actcell < cell; ++i) {
3398 if (c == LyXParagraph::META_NEWLINE)
3403 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3406 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3408 font2 = GetFontSettings(i);
3409 if (font1.latex() != font2.latex()) {
3410 if (font2.latex() != LyXFont::OFF)
3415 case LyXParagraph::META_INSET:
3416 if ((inset = GetInset(i))) {
3418 stringstream ss(ios::in | ios::out);
3445 case LyXParagraph::META_NEWLINE:
3447 case LyXParagraph::META_HFILL:
3456 lyxerr.debug() << "RoffAsciiTable: "
3457 "NULL char in structure."
3462 cell = table->CellHasContRow(actcell);
3469 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3471 TexRow & foot_texrow,
3474 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3475 LyXParagraph * par = this;
3478 (par->depth == depth) &&
3479 (par->footnoteflag == footnoteflag)) {
3481 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3482 if (textclasslist.Style(current_view->buffer()->params.textclass,
3483 par->layout).isEnvironment()
3484 || par->pextra_type != PEXTRA_NONE) {
3485 par = par->TeXEnvironment(os, texrow,
3489 par = par->TeXOnePar(os, texrow, false,
3494 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3500 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3502 TexRow & foot_texrow,
3505 bool eindent_open = false;
3506 bool foot_this_level = false;
3507 // flags when footnotetext should be appended to file.
3508 static bool minipage_open = false;
3509 static int minipage_open_depth = 0;
3510 char par_sep = current_view->buffer()->params.paragraph_separation;
3512 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3514 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3516 LyXLayout const & style =
3517 textclasslist.Style(current_view->buffer()->params.textclass,
3520 if (pextra_type == PEXTRA_INDENT) {
3521 if (!pextra_width.empty()) {
3522 os << "\\begin{LyXParagraphIndent}{"
3523 << pextra_width << "}\n";
3525 //float ib = atof(pextra_widthp.c_str())/100;
3526 // string can't handle floats at present (971109)
3527 // so I'll do a conversion by hand knowing that
3528 // the limits are 0.0 to 1.0. ARRae.
3529 os << "\\begin{LyXParagraphIndent}{";
3530 switch (pextra_widthp.length()) {
3542 os << "\\columnwidth}\n";
3545 eindent_open = true;
3547 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3548 if (pextra_hfill && Previous() &&
3549 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3550 os << "\\hfill{}\n";
3553 if (par_sep == BufferParams::PARSEP_INDENT) {
3554 os << "{\\setlength\\parindent{0pt}\n";
3557 os << "\\begin{minipage}";
3558 switch(pextra_alignment) {
3559 case MINIPAGE_ALIGN_TOP:
3562 case MINIPAGE_ALIGN_MIDDLE:
3565 case MINIPAGE_ALIGN_BOTTOM:
3569 if (!pextra_width.empty()) {
3570 os << '{' << pextra_width << "}\n";
3572 //float ib = atof(par->pextra_width.c_str())/100;
3573 // string can't handle floats at present
3574 // so I'll do a conversion by hand knowing that
3575 // the limits are 0.0 to 1.0. ARRae.
3577 switch (pextra_widthp.length()) {
3589 os << "\\columnwidth}\n";
3592 if (par_sep == BufferParams::PARSEP_INDENT) {
3593 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3596 minipage_open = true;
3597 minipage_open_depth = depth;
3600 #ifdef WITH_WARNINGS
3601 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3602 //I disabled it because it breaks when lists span on several
3605 if (style.isEnvironment()){
3606 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3607 #ifdef FANCY_FOOTNOTE_CODE
3608 if (foot_count < 0) {
3609 // flag that footnote[mark][text] should be
3610 // used for any footnotes from now on
3612 foot_this_level = true;
3615 os << "\\begin{" << style.latexname() << "}{"
3616 << labelwidthstring << "}\n";
3617 } else if (style.labeltype == LABEL_BIBLIO) {
3619 os << "\\begin{" << style.latexname() << "}{"
3620 << bibitemWidthest(current_view->painter())
3622 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3623 #ifdef FANCY_FOOTNOTE_CODE
3624 if (foot_count < 0) {
3625 // flag that footnote[mark][text] should be
3626 // used for any footnotes from now on
3628 foot_this_level = true;
3631 os << "\\begin{" << style.latexname() << '}'
3632 << style.latexparam() << '\n';
3634 os << "\\begin{" << style.latexname() << '}'
3635 << style.latexparam() << '\n';
3638 LyXParagraph * par = this;
3640 par = par->TeXOnePar(os, texrow, false,
3641 foot, foot_texrow, foot_count);
3643 if (minipage_open && par && !style.isEnvironment() &&
3644 (par->pextra_type == PEXTRA_MINIPAGE) &&
3645 par->pextra_start_minipage) {
3646 os << "\\end{minipage}\n";
3648 if (par_sep == BufferParams::PARSEP_INDENT) {
3652 minipage_open = false;
3654 if (par && par->depth > depth) {
3655 if (textclasslist.Style(current_view->buffer()->params.textclass,
3656 par->layout).isParagraph()
3659 // How to handle this? (Lgb)
3660 //&& !suffixIs(os, "\n\n")
3662 // There should be at least one '\n' already
3663 // but we need there to be two for Standard
3664 // paragraphs that are depth-increment'ed to be
3665 // output correctly. However, tables can
3666 // also be paragraphs so don't adjust them.
3669 // Will it ever harm to have one '\n' too
3670 // many? i.e. that we sometimes will have
3671 // three in a row. (Lgb)
3675 par = par->TeXDeeper(os, texrow,
3676 foot, foot_texrow, foot_count);
3678 if (par && par->layout == layout && par->depth == depth &&
3679 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3680 if (par->pextra_hfill && par->Previous() &&
3681 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3682 os << "\\hfill{}\n";
3685 if (par_sep == BufferParams::PARSEP_INDENT) {
3686 os << "{\\setlength\\parindent{0pt}\n";
3689 os << "\\begin{minipage}";
3690 switch(par->pextra_alignment) {
3691 case MINIPAGE_ALIGN_TOP:
3694 case MINIPAGE_ALIGN_MIDDLE:
3697 case MINIPAGE_ALIGN_BOTTOM:
3701 if (!par->pextra_width.empty()) {
3702 os << '{' << par->pextra_width << "}\n";
3704 //float ib = atof(par->pextra_widthp.c_str())/100;
3705 // string can't handle floats at present
3706 // so I'll do a conversion by hand knowing that
3707 // the limits are 0.0 to 1.0. ARRae.
3709 switch (par->pextra_widthp.length()) {
3714 os << "0." << par->pextra_widthp;
3717 os << "0.0" << par->pextra_widthp;
3719 os << "\\columnwidth}\n";
3722 if (par_sep == BufferParams::PARSEP_INDENT) {
3723 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3726 minipage_open = true;
3727 minipage_open_depth = par->depth;
3730 && par->layout == layout
3731 && par->depth == depth
3732 && par->pextra_type == pextra_type
3733 && par->footnoteflag == footnoteflag);
3735 if (style.isEnvironment()) {
3736 os << "\\end{" << style.latexname() << '}';
3737 // maybe this should go after the minipage closes?
3738 if (foot_this_level) {
3739 if (foot_count >= 1) {
3740 if (foot_count > 1) {
3741 os << "\\addtocounter{footnote}{-"
3746 texrow += foot_texrow;
3748 foot_texrow.reset();
3753 if (minipage_open && (minipage_open_depth == depth) &&
3754 (!par || par->pextra_start_minipage ||
3755 par->pextra_type != PEXTRA_MINIPAGE)) {
3756 os << "\\end{minipage}\n";
3758 if (par_sep == BufferParams::PARSEP_INDENT) {
3762 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3763 os << "\\medskip\n\n";
3767 minipage_open = false;
3770 os << "\\end{LyXParagraphIndent}\n";
3773 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3774 && par->pextra_hfill)) {
3778 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3779 return par; // ale970302
3783 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3784 ostream & foot, TexRow & foot_texrow,
3788 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3789 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3790 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3791 "No footnote!" << endl;
3793 LyXParagraph * par = this;
3794 LyXLayout const & style =
3795 textclasslist.Style(current_view->buffer()->params.textclass,
3796 previous->GetLayout());
3798 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3799 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3800 "Float other than footnote in command"
3801 " with moving argument is illegal" << endl;
3804 if (footnotekind != LyXParagraph::FOOTNOTE
3805 && footnotekind != LyXParagraph::MARGIN
3808 // How to solve this?
3809 //&& !suffixIs(file, '\n')
3811 // we need to ensure that real floats like tables and figures
3812 // have their \begin{} on a new line otherwise we can get
3813 // incorrect results when using the endfloat.sty package
3814 // especially if two floats follow one another. ARRae 981022
3815 // NOTE: if the file is length 0 it must have just been
3816 // written out so we assume it ended with a '\n'
3818 // As far as I can see there is never any harm in writing
3819 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3824 bool moving_arg = false;
3825 bool need_closing = false;
3826 bool is_rtl = isRightToLeftPar();
3828 if (is_rtl != parent_is_rtl) {
3833 need_closing = true;
3836 BufferParams * params = ¤t_view->buffer()->params;
3837 bool footer_in_body = true;
3838 switch (footnotekind) {
3839 case LyXParagraph::FOOTNOTE:
3840 if (style.intitle) {
3841 os << "\\thanks{\n";
3842 footer_in_body = false;
3845 if (foot_count == -1) {
3846 // we're at depth 0 so we can use:
3847 os << "\\footnote{%\n";
3848 footer_in_body = false;
3850 os << "\\footnotemark{}%\n";
3852 // we only need this when there are
3853 // multiple footnotes
3854 os << "\\stepcounter{footnote}";
3856 os << "\\footnotetext{%\n";
3857 foot_texrow.start(this, 0);
3858 foot_texrow.newline();
3863 case LyXParagraph::MARGIN:
3864 os << "\\marginpar{\n";
3866 case LyXParagraph::FIG:
3867 if (pextra_type == PEXTRA_FLOATFLT
3868 && (!pextra_width.empty()
3869 || !pextra_widthp.empty())) {
3870 if (!pextra_width.empty())
3871 os << "\\begin{floatingfigure}{"
3872 << pextra_width << "}\n";
3874 os << "\\begin{floatingfigure}{"
3875 << atoi(pextra_widthp.c_str())/100.0
3876 << "\\textwidth}\n";
3878 os << "\\begin{figure}";
3879 if (!params->float_placement.empty()) {
3880 os << '[' << params->float_placement << "]\n";
3886 case LyXParagraph::TAB:
3887 os << "\\begin{table}";
3888 if (!params->float_placement.empty()) {
3889 os << '[' << params->float_placement << "]\n";
3894 case LyXParagraph::WIDE_FIG:
3895 os << "\\begin{figure*}";
3896 if (!params->float_placement.empty()) {
3897 os << '[' << params->float_placement << "]\n";
3902 case LyXParagraph::WIDE_TAB:
3903 os << "\\begin{table*}";
3904 if (!params->float_placement.empty()) {
3905 os << '[' << params->float_placement << "]\n";
3910 case LyXParagraph::ALGORITHM:
3911 os << "\\begin{algorithm}\n";
3916 if (footnotekind != LyXParagraph::FOOTNOTE
3917 || !footer_in_body) {
3918 // Process text for all floats except footnotes in body
3920 LyXLayout const & style =
3922 .Style(current_view->buffer()->params
3926 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3928 if (style.isEnvironment()
3929 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3930 // Allows the use of minipages within float
3931 // environments. Shouldn't be circular because
3932 // we don't support footnotes inside
3933 // floats (yet). ARRae
3934 par = par->TeXEnvironment(os, texrow,
3938 par = par->TeXOnePar(os, texrow, moving_arg,
3943 if (par && !par->IsDummy() && par->depth > depth) {
3944 par = par->TeXDeeper(os, texrow,
3948 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3950 // process footnotes > depth 0 or in environments separately
3951 // NOTE: Currently don't support footnotes within footnotes
3952 // even though that is possible using the \footnotemark
3954 std::ostringstream dummy;
3958 TexRow dummy_texrow;
3959 int dummy_count = 0;
3961 LyXLayout const & style =
3963 .Style(current_view->buffer()->params
3967 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3969 if (style.isEnvironment()
3970 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3971 // Allows the use of minipages within float
3972 // environments. Shouldn't be circular because
3973 // we don't support footnotes inside
3974 // floats (yet). ARRae
3975 par = par->TeXEnvironment(foot, foot_texrow,
3976 dummy, dummy_texrow,
3979 par = par->TeXOnePar(foot, foot_texrow,
3981 dummy, dummy_texrow,
3985 if (par && !par->IsDummy() && par->depth > depth) {
3986 par = par->TeXDeeper(foot, foot_texrow,
3987 dummy, dummy_texrow,
3991 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3993 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3994 "Footnote in a Footnote -- not supported"
3997 #ifndef HAVE_OSTREAM
3998 delete [] dummy.str();
4002 switch (footnotekind) {
4003 case LyXParagraph::FOOTNOTE:
4004 if (footer_in_body) {
4005 // This helps tell which of the multiple
4006 // footnotetexts an error was in.
4008 foot_texrow.newline();
4013 case LyXParagraph::MARGIN:
4016 case LyXParagraph::FIG:
4017 if (pextra_type == PEXTRA_FLOATFLT
4018 && (!pextra_width.empty()
4019 || !pextra_widthp.empty()))
4020 os << "\\end{floatingfigure}";
4022 os << "\\end{figure}";
4024 case LyXParagraph::TAB:
4025 os << "\\end{table}";
4027 case LyXParagraph::WIDE_FIG:
4028 os << "\\end{figure*}";
4030 case LyXParagraph::WIDE_TAB:
4031 os << "\\end{table*}";
4033 case LyXParagraph::ALGORITHM:
4034 os << "\\end{algorithm}";
4041 if (footnotekind != LyXParagraph::FOOTNOTE
4042 && footnotekind != LyXParagraph::MARGIN) {
4043 // we need to ensure that real floats like tables and figures
4044 // have their \end{} on a line of their own otherwise we can
4045 // get incorrect results when using the endfloat.sty package.
4050 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4055 bool LyXParagraph::IsDummy() const
4057 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4058 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4062 void LyXParagraph::SetPExtraType(int type, char const * width,
4063 char const * widthp)
4066 pextra_width = width;
4067 pextra_widthp = widthp;
4069 if (textclasslist.Style(current_view->buffer()->params.textclass,
4070 layout).isEnvironment()) {
4075 while (par && (par->layout == layout)
4076 && (par->depth == depth)) {
4078 par = par->Previous();
4080 par = par->FirstPhysicalPar();
4081 while (par && par->depth > depth) {
4082 par = par->Previous();
4084 par = par->FirstPhysicalPar();
4088 while (par && (par->layout == layout)
4089 && (par->depth == depth)) {
4090 par->pextra_type = type;
4091 par->pextra_width = width;
4092 par->pextra_widthp = widthp;
4093 par = par->NextAfterFootnote();
4094 if (par && (par->depth > depth))
4095 par->SetPExtraType(type, width, widthp);
4096 while (par && ((par->depth > depth) || par->IsDummy()))
4097 par = par->NextAfterFootnote();
4103 void LyXParagraph::UnsetPExtraType()
4105 if (pextra_type == PEXTRA_NONE)
4108 pextra_type = PEXTRA_NONE;
4109 pextra_width.erase();
4110 pextra_widthp.erase();
4112 if (textclasslist.Style(current_view->buffer()->params.textclass,
4113 layout).isEnvironment()) {
4118 while (par && (par->layout == layout)
4119 && (par->depth == depth)) {
4121 par = par->Previous();
4123 par = par->FirstPhysicalPar();
4124 while (par && par->depth > depth) {
4125 par = par->Previous();
4127 par = par->FirstPhysicalPar();
4131 while (par && (par->layout == layout)
4132 && (par->depth == depth)) {
4133 par->pextra_type = PEXTRA_NONE;
4134 par->pextra_width.erase();
4135 par->pextra_widthp.erase();
4136 par = par->NextAfterFootnote();
4137 if (par && (par->depth > depth))
4138 par->UnsetPExtraType();
4139 while (par && ((par->depth > depth) || par->IsDummy()))
4140 par = par->NextAfterFootnote();
4146 bool LyXParagraph::IsHfill(size_type pos) const
4148 return IsHfillChar(GetChar(pos));
4152 bool LyXParagraph::IsInset(size_type pos) const
4154 return IsInsetChar(GetChar(pos));
4158 bool LyXParagraph::IsFloat(size_type pos) const
4160 return IsFloatChar(GetChar(pos));
4164 bool LyXParagraph::IsNewline(size_type pos) const
4166 return pos >= 0 && IsNewlineChar(GetChar(pos));
4170 bool LyXParagraph::IsSeparator(size_type pos) const
4172 return IsSeparatorChar(GetChar(pos));
4176 bool LyXParagraph::IsLineSeparator(size_type pos) const
4178 return IsLineSeparatorChar(GetChar(pos));
4182 bool LyXParagraph::IsKomma(size_type pos) const
4184 return IsKommaChar(GetChar(pos));
4188 /// Used by the spellchecker
4189 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4191 unsigned char c = GetChar(pos);
4192 if (IsLetterChar(c))
4194 // '\0' is not a letter, allthough every string contains "" (below)
4197 // We want to pass the ' and escape chars to ispell
4198 string extra = lyxrc.isp_esc_chars + '\'';
4202 return contains(extra, ch);
4206 bool LyXParagraph::IsWord(size_type pos ) const
4208 return IsWordChar(GetChar(pos)) ;
4212 Language const * LyXParagraph::getParLanguage() const
4216 return FirstPhysicalPar()->GetFirstFontSettings()
4219 for (size_type pos = 0; pos < size(); ++pos)
4221 return GetFontSettings(pos).language();
4222 return GetFirstFontSettings().language();
4225 return previous->getParLanguage();
4227 return current_view->buffer()->params.language_info;
4231 bool LyXParagraph::isRightToLeftPar() const
4233 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4237 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4239 for(size_type i = 0; i < size(); ++i) {
4240 LyXFont font = GetFontSettings(i);
4241 if (font.language() == from) {
4242 font.setLanguage(to);
4249 bool LyXParagraph::isMultiLingual()
4251 Language const * doc_language =
4252 current_view->buffer()->params.language_info;
4253 for(size_type i = 0; i < size(); ++i) {
4254 LyXFont font = GetFontSettings(i);
4255 if (font.language() != doc_language)
4262 // Convert the paragraph to a string.
4263 // Used for building the table of contents
4264 string LyXParagraph::String(bool label)
4267 if (label && !IsDummy())
4268 s += labelstring + ' ';
4269 string::size_type len = s.size();
4271 for (LyXParagraph::size_type i = 0;i < size(); ++i) {
4272 unsigned char c = GetChar(i);
4275 else if (c == META_INSET &&
4276 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4278 std::ostringstream ost;
4279 GetInset(i)->Ascii(ost);
4282 GetInset(i)->Ascii(ost);
4285 s += subst(ost.str(),'\n',' ');
4289 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4290 s += NextAfterFootnote()->String(false);
4293 if (isRightToLeftPar())
4294 reverse(s.begin() + len,s.end());