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"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
25 #include "tex-strings.h"
26 #include "bufferparams.h"
27 #include "support/FileInfo.h"
28 #include "support/LAssert.h"
30 #include "LaTeXFeatures.h"
31 #include "insets/insetinclude.h"
32 #include "insets/insetbib.h"
33 #include "insets/insettext.h"
34 #include "support/filetools.h"
35 #include "lyx_gui_misc.h"
37 #include "support/lyxmanip.h"
38 #include "BufferView.h"
44 using std::lower_bound;
45 using std::upper_bound;
48 int tex_code_break_column = 72; // needs non-zero initialization. set later.
49 // this is a bad idea, but how can LyXParagraph find its buffer to get
50 // parameters? (JMarc)
51 extern BufferView * current_view;
52 extern string bibitemWidest(Painter &);
54 // this is a minibuffer
55 static char minibuffer_char;
56 static LyXFont minibuffer_font;
57 static Inset * minibuffer_inset;
60 // Initialization of the counter for the paragraph id's,
61 // declared in lyxparagraph.h
62 unsigned int LyXParagraph::paragraph_id = 0;
65 LyXParagraph::LyXParagraph()
67 text.reserve(500); // is this number too big?
69 for (int i = 0; i < 10; ++i) setCounter(i , 0);
76 footnoteflag = LyXParagraph::NO_FOOTNOTE;
77 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
79 align = LYX_ALIGN_BLOCK;
82 /* table stuff -- begin*/
84 /* table stuff -- end*/
88 bibkey = 0; // ale970302
93 // This konstruktor inserts the new paragraph in a list.
94 LyXParagraph::LyXParagraph(LyXParagraph * par)
97 par->text.resize(par->text.size());
99 for (int i = 0; i < 10; ++i) setCounter(i, 0);
103 // double linked list begin
106 next->previous = this;
108 previous->next = this;
111 footnoteflag = LyXParagraph::NO_FOOTNOTE;
112 footnotekind = LyXParagraph::FOOTNOTE;
115 /* table stuff -- begin*/
117 /* table stuff -- end*/
120 id_ = paragraph_id++;
122 bibkey = 0; // ale970302
128 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
129 BufferParams const & params,
130 char footflag, char dth) const
132 LyXFont font1, font2;
137 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
139 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
141 // The beginning or the end of a footnote environment?
142 if (footflag != footnoteflag) {
143 footflag = footnoteflag;
145 os << "\n\\begin_float "
146 << string_footnotekinds[footnotekind]
149 os << "\n\\end_float ";
153 // The beginning or end of a deeper (i.e. nested) area?
156 while (depth > dth) {
157 os << "\n\\begin_deeper ";
161 while (depth < dth) {
162 os << "\n\\end_deeper ";
168 // First write the layout
170 << textclasslist.NameOfLayout(params.textclass, layout)
173 // Maybe some vertical spaces.
174 if (added_space_top.kind() != VSpace::NONE)
175 os << "\\added_space_top "
176 << added_space_top.asLyXCommand() << " ";
177 if (added_space_bottom.kind() != VSpace::NONE)
178 os << "\\added_space_bottom "
179 << added_space_bottom.asLyXCommand() << " ";
181 // Maybe the paragraph has special spacing
182 spacing.writeFile(os, true);
184 // The labelwidth string used in lists.
185 if (!labelwidthstring.empty())
186 os << "\\labelwidthstring "
187 << labelwidthstring << '\n';
189 // Lines above or below?
193 os << "\\line_bottom ";
195 // Pagebreaks above or below?
197 os << "\\pagebreak_top ";
198 if (pagebreak_bottom)
199 os << "\\pagebreak_bottom ";
201 // Start of appendix?
202 if (start_of_appendix)
203 os << "\\start_of_appendix ";
210 if (align != LYX_ALIGN_LAYOUT) {
212 case LYX_ALIGN_LEFT: h = 1; break;
213 case LYX_ALIGN_RIGHT: h = 2; break;
214 case LYX_ALIGN_CENTER: h = 3; break;
215 default: h = 0; break;
217 os << "\\align " << string_align[h] << " ";
219 if (pextra_type != PEXTRA_NONE) {
220 os << "\\pextra_type " << pextra_type;
221 if (pextra_type == PEXTRA_MINIPAGE) {
222 os << " \\pextra_alignment "
225 os << " \\pextra_hfill "
227 if (pextra_start_minipage)
228 os << " \\pextra_start_minipage "
229 << pextra_start_minipage;
231 if (!pextra_width.empty()) {
232 os << " \\pextra_width "
233 << VSpace(pextra_width).asLyXCommand();
234 } else if (!pextra_widthp.empty()) {
235 os << " \\pextra_widthp "
241 // Dummy layout. This means that a footnote ended.
242 os << "\n\\end_float ";
243 footflag = LyXParagraph::NO_FOOTNOTE;
246 // It might be a table.
248 os << "\\LyXTable\n";
254 bibkey->Write(buf, os);
256 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
259 for (size_type i = 0; i < size(); ++i) {
265 // Write font changes
266 font2 = GetFontSettings(params, i);
267 if (font2 != font1) {
268 font2.lyxWriteChanges(font1, os);
277 Inset const * inset = GetInset(i);
279 if (inset->DirectWrite()) {
280 // international char, let it write
281 // code directly so it's shorter in
283 inset->Write(buf, os);
285 os << "\n\\begin_inset ";
286 inset->Write(buf, os);
287 os << "\n\\end_inset \n\n";
293 os << "\n\\newline \n";
297 os << "\n\\hfill \n";
301 os << "\n\\backslash \n";
305 if (i + 1 < size() && GetChar(i + 1) == ' ') {
312 if ((column > 70 && c == ' ')
317 // this check is to amend a bug. LyX sometimes
318 // inserts '\0' this could cause problems.
322 lyxerr << "ERROR (LyXParagraph::writeFile):"
323 " NULL char in structure." << endl;
329 // now write the next paragraph
331 next->writeFile(buf, os, params, footflag, dth);
335 void LyXParagraph::validate(LaTeXFeatures & features) const
337 BufferParams const & params = features.bufferParams();
339 // this will be useful later
340 LyXLayout const & layout =
341 textclasslist.Style(params.textclass,
345 if (line_top || line_bottom)
346 features.lyxline = true;
347 if (!spacing.isDefault())
348 features.setspace = true;
351 features.layout[GetLayout()] = true;
354 Language const * doc_language = params.language_info;
356 for (FontList::const_iterator cit = fontlist.begin();
357 cit != fontlist.end(); ++cit) {
358 if ((*cit).font.noun() == LyXFont::ON) {
359 lyxerr[Debug::LATEX] << "font.noun: "
360 << (*cit).font.noun()
362 features.noun = true;
363 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
364 << (*cit).font.stateText(0)
367 switch ((*cit).font.color()) {
369 case LColor::inherit:
373 features.color = true;
374 lyxerr[Debug::LATEX] << "Color enabled. Font: "
375 << (*cit).font.stateText(0)
379 Language const * language = (*cit).font.language();
380 if (language != doc_language) {
381 features.UsedLanguages.insert(language);
382 lyxerr[Debug::LATEX] << "Found language "
383 << language->lang() << endl;
388 for (InsetList::const_iterator cit = insetlist.begin();
389 cit != insetlist.end(); ++cit) {
391 (*cit).inset->Validate(features);
394 if (table && table->IsLongTable())
395 features.longtable = true;
396 if (pextra_type == PEXTRA_INDENT)
397 features.LyXParagraphIndent = true;
398 if (pextra_type == PEXTRA_FLOATFLT)
399 features.floatflt = true;
400 if (layout.needprotect
401 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
402 features.NeedLyXFootnoteCode = true;
403 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
404 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
405 features.NeedLyXMinipageIndent = true;
406 if (table && table->NeedRotating())
407 features.rotating = true;
408 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
409 features.algorithm = true;
413 // First few functions needed for cut and paste and paragraph breaking.
414 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
415 LyXParagraph::size_type pos) const
417 minibuffer_char = GetChar(pos);
418 minibuffer_font = GetFontSettings(bparams, 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(BufferParams const & bparams,
433 LyXParagraph::size_type pos)
435 minibuffer_char = GetChar(pos);
436 minibuffer_font = GetFontSettings(bparams, pos);
437 minibuffer_inset = 0;
438 if (minibuffer_char == LyXParagraph::META_INSET) {
440 minibuffer_inset = GetInset(pos);
441 // This is a little hack since I want exactly
442 // the inset, not just a clone. Otherwise
443 // the inset would be deleted when calling Erase(pos)
445 InsetList::iterator it = lower_bound(insetlist.begin(),
448 if (it != insetlist.end() && (*it).pos == pos)
451 minibuffer_inset = 0;
452 minibuffer_char = ' ';
453 // This reflects what GetInset() does (ARRae)
458 // Erase(pos); now the caller is responsible for that.
462 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
464 if ((minibuffer_char == LyXParagraph::META_INSET) &&
465 !InsertInsetAllowed(minibuffer_inset))
467 if (minibuffer_char == LyXParagraph::META_INSET)
468 InsertInset(pos, minibuffer_inset, minibuffer_font);
470 InsertChar(pos, minibuffer_char, minibuffer_font);
478 void LyXParagraph::Clear()
483 pagebreak_top = false;
484 pagebreak_bottom = false;
486 added_space_top = VSpace(VSpace::NONE);
487 added_space_bottom = VSpace(VSpace::NONE);
488 spacing.set(Spacing::Default);
490 align = LYX_ALIGN_LAYOUT;
494 pextra_type = PEXTRA_NONE;
495 pextra_width.erase();
496 pextra_widthp.erase();
497 pextra_alignment = MINIPAGE_ALIGN_TOP;
498 pextra_hfill = false;
499 pextra_start_minipage = false;
502 labelwidthstring.erase();
506 start_of_appendix = false;
510 // the destructor removes the new paragraph from the list
511 LyXParagraph::~LyXParagraph()
514 previous->next = next;
516 next->previous = previous;
518 for (InsetList::iterator it = insetlist.begin();
519 it != insetlist.end(); ++it) {
523 /* table stuff -- begin*/
525 /* table stuff -- end*/
531 //lyxerr << "LyXParagraph::paragraph_id = "
532 // << LyXParagraph::paragraph_id << endl;
536 void LyXParagraph::Erase(LyXParagraph::size_type pos)
538 // > because last is the next unused position, and you can
539 // use it if you want
542 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
543 NextAfterFootnote()->Erase(pos - text.size() - 1);
546 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
547 "position does not exist." << endl;
550 if (pos < size()) { // last is free for insertation, but should be empty
551 // if it is an inset, delete the inset entry
552 if (text[pos] == LyXParagraph::META_INSET) {
554 InsetList::iterator it = lower_bound(insetlist.begin(),
557 if (it != insetlist.end() && (*it).pos == pos) {
562 text.erase(text.begin() + pos);
564 // Erase entries in the tables.
565 FontList::iterator it = lower_bound(fontlist.begin(),
568 if (it != fontlist.end() && (*it).pos == pos &&
570 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
571 // If it is a multi-character font
572 // entry, we just make it smaller
573 // (see update below), otherwise we
575 unsigned int i = it - fontlist.begin();
576 fontlist.erase(fontlist.begin() + i);
577 it = fontlist.begin() + i;
578 if (i > 0 && i < fontlist.size() &&
579 fontlist[i-1].font == fontlist[i].font) {
580 fontlist.erase(fontlist.begin() + i-1);
581 it = fontlist.begin() + i-1;
585 // Update all other entries.
586 for (; it != fontlist.end(); ++it)
589 // Update the inset table.
590 for (InsetList::iterator it = upper_bound(insetlist.begin(),
593 it != insetlist.end(); ++it)
596 lyxerr << "ERROR (LyXParagraph::Erase): "
597 "can't erase non-existant char." << endl;
602 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
604 LyXFont f(LyXFont::ALL_INHERIT);
605 InsertChar(pos, c, f);
609 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
610 char c, LyXFont const & font)
612 // > because last is the next unused position, and you can
613 // use it if you want
617 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
618 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
622 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
623 "position does not exist." << endl;
626 text.insert(text.begin() + pos, c);
627 // Update the font table.
628 for (FontList::iterator it = lower_bound(fontlist.begin(),
631 it != fontlist.end(); ++it)
634 // Update the inset table.
635 for (InsetList::iterator it = lower_bound(insetlist.begin(),
638 it != insetlist.end(); ++it)
645 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
648 LyXFont f(LyXFont::ALL_INHERIT);
649 InsertInset(pos, inset, f);
653 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
654 Inset * inset, LyXFont const & font)
658 // > because last is the next unused position, and you can
659 // use it if you want
663 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
665 ->InsertInset(pos - text.size() - 1,
669 lyxerr << "ERROR (LyXParagraph::InsertInset): "
670 "position does not exist: " << pos << endl;
674 InsertChar(pos, META_INSET, font);
675 Assert(text[pos] == META_INSET);
677 // Add a new entry in the inset table.
678 InsetList::iterator it = lower_bound(insetlist.begin(),
681 if (it != insetlist.end() && (*it).pos == pos)
682 lyxerr << "ERROR (LyXParagraph::InsertInset): "
683 "there is an inset in position: " << pos << endl;
685 insetlist.insert(it, InsetTable(pos, inset));
687 inset->setOwner(inset_owner);
691 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
693 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
696 return inset_owner->InsertInsetAllowed(inset);
701 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
706 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
707 return NextAfterFootnote()
708 ->GetInset(pos - text.size() - 1);
711 lyxerr << "ERROR (LyXParagraph::GetInset): "
712 "position does not exist: "
718 InsetList::iterator it = lower_bound(insetlist.begin(),
721 if (it != insetlist.end() && (*it).pos == pos)
724 lyxerr << "ERROR (LyXParagraph::GetInset): "
725 "Inset does not exist: " << pos << endl;
728 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
729 // Did this commenting out introduce a bug? So far I have not
730 // see any, please enlighten me. (Lgb)
731 // My guess is that since the inset does not exist, we might
732 // as well replace it with a space to prevent craches. (Asger)
737 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
742 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
743 return NextAfterFootnote()
744 ->GetInset(pos - text.size() - 1);
747 lyxerr << "ERROR (LyXParagraph::GetInset): "
748 "position does not exist: "
754 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
757 if (cit != insetlist.end() && (*cit).pos == pos)
760 lyxerr << "ERROR (LyXParagraph::GetInset): "
761 "Inset does not exist: " << pos << endl;
763 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
764 // Did this commenting out introduce a bug? So far I have not
765 // see any, please enlighten me. (Lgb)
766 // My guess is that since the inset does not exist, we might
767 // as well replace it with a space to prevent craches. (Asger)
772 // Gets uninstantiated font setting at position.
773 // Optimized after profiling. (Asger)
774 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
775 LyXParagraph::size_type pos) const
778 FontList::const_iterator cit = lower_bound(fontlist.begin(),
781 if (cit != fontlist.end())
784 // > because last is the next unused position, and you can
785 // use it if you want
786 else if (pos > size()) {
789 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
790 return NextAfterFootnote()
791 ->GetFontSettings(bparams,
792 pos - text.size() - 1);
795 // Why is it an error to ask for the font of a
796 // position that does not exist? Would it be
797 // enough for this to be enabled on debug?
798 // We want strict error checking, but it's ok to only
799 // have it when debugging. (Asger)
800 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
801 "position does not exist. "
802 << pos << " (" << static_cast<int>(pos)
804 } else if (pos > 0) {
805 return GetFontSettings(bparams, pos - 1);
806 } else // pos = size() = 0
807 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
809 return LyXFont(LyXFont::ALL_INHERIT);
812 // Gets uninstantiated font setting at position 0
813 LyXFont LyXParagraph::GetFirstFontSettings() const
816 if (!fontlist.empty())
817 return fontlist[0].font;
821 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
822 return NextAfterFootnote()->GetFirstFontSettings();
824 return LyXFont(LyXFont::ALL_INHERIT);
828 // Gets the fully instantiated font at a given position in a paragraph
829 // This is basically the same function as LyXText::GetFont() in text2.C.
830 // The difference is that this one is used for generating the LaTeX file,
831 // and thus cosmetic "improvements" are disallowed: This has to deliver
832 // the true picture of the buffer. (Asger)
833 // If position is -1, we get the layout font of the paragraph.
834 // If position is -2, we get the font of the manual label of the paragraph.
835 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
836 LyXParagraph::size_type pos) const
839 LyXLayout const & layout =
840 textclasslist.Style(bparams.textclass,
842 LyXParagraph::size_type main_body = 0;
843 if (layout.labeltype == LABEL_MANUAL)
844 main_body = BeginningOfMainBody();
849 layoutfont = layout.labelfont;
851 layoutfont = layout.font;
852 tmpfont = GetFontSettings(bparams, pos);
853 tmpfont.realize(layoutfont);
855 // process layoutfont for pos == -1 and labelfont for pos < -1
857 tmpfont = layout.font;
859 tmpfont = layout.labelfont;
860 tmpfont.setLanguage(getParLanguage(bparams));
863 // check for environment font information
864 char par_depth = GetDepth();
865 LyXParagraph const * par = this;
866 while (par && par_depth && !tmpfont.resolved()) {
867 par = par->DepthHook(par_depth - 1);
869 tmpfont.realize(textclasslist.
870 Style(bparams.textclass,
871 par->GetLayout()).font);
872 par_depth = par->GetDepth();
876 tmpfont.realize(textclasslist
877 .TextClass(bparams.textclass)
883 /// Returns the height of the highest font in range
885 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
886 LyXParagraph::size_type endpos) const
888 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
889 if (fontlist.empty())
892 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
895 if (end_it != fontlist.end())
898 for (FontList::const_iterator cit = lower_bound(fontlist.begin(),
900 startpos, matchFT());
901 cit != end_it; ++cit) {
902 LyXFont::FONT_SIZE size = (*cit).font.size();
903 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
910 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
917 // > because last is the next unused position, and you can
918 // use it if you want
919 else if (pos > size()) {
921 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
922 return NextAfterFootnote()
923 ->GetChar(pos - text.size() - 1);
927 lyxerr << "ERROR (LyXParagraph::GetChar): "
928 "position does not exist."
929 << pos << " (" << static_cast<int>(pos)
931 // Assert(false); // This triggers sometimes...
940 // We should have a footnote environment.
941 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
942 // Notice that LyX does request the
943 // last char from time to time. (Asger)
944 //lyxerr << "ERROR (LyXParagraph::GetChar): "
945 // "expected footnote." << endl;
948 switch (next->footnotekind) {
949 case LyXParagraph::FOOTNOTE:
950 return LyXParagraph::META_FOOTNOTE;
951 case LyXParagraph::MARGIN:
952 return LyXParagraph::META_MARGIN;
953 case LyXParagraph::FIG:
954 case LyXParagraph::WIDE_FIG:
955 return LyXParagraph::META_FIG;
956 case LyXParagraph::TAB:
957 case LyXParagraph::WIDE_TAB:
958 return LyXParagraph::META_TAB;
959 case LyXParagraph::ALGORITHM:
960 return LyXParagraph::META_ALGORITHM;
962 return '\0'; // to shut up gcc
968 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
975 // > because last is the next unused position, and you can
976 // use it if you want
977 else if (pos > size()) {
979 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
980 return NextAfterFootnote()
981 ->GetChar(pos - text.size() - 1);
985 lyxerr << "ERROR (LyXParagraph::GetChar const): "
986 "position does not exist."
987 << pos << " (" << static_cast<int>(pos)
995 // We should have a footnote environment.
996 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
997 // Notice that LyX does request the
998 // last char from time to time. (Asger)
999 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1000 // "expected footnote." << endl;
1003 switch (next->footnotekind) {
1004 case LyXParagraph::FOOTNOTE:
1005 return LyXParagraph::META_FOOTNOTE;
1006 case LyXParagraph::MARGIN:
1007 return LyXParagraph::META_MARGIN;
1008 case LyXParagraph::FIG:
1009 case LyXParagraph::WIDE_FIG:
1010 return LyXParagraph::META_FIG;
1011 case LyXParagraph::TAB:
1012 case LyXParagraph::WIDE_TAB:
1013 return LyXParagraph::META_TAB;
1014 case LyXParagraph::ALGORITHM:
1015 return LyXParagraph::META_ALGORITHM;
1017 return '\0'; // to shut up gcc
1023 // return an string of the current word, and the end of the word in lastpos.
1024 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1028 // the current word is defined as starting at the first character
1029 // from the immediate left of lastpospos which meets the definition
1030 // of IsLetter(), continuing to the last character to the right
1031 // of this meeting IsLetter.
1037 // move back until we have a letter
1039 //there's no real reason to have firstpos & lastpos as
1040 //separate variables as this is written, but maybe someon
1041 // will want to return firstpos in the future.
1043 //since someone might have typed a punctuation first
1044 int firstpos = lastpos;
1046 while ((firstpos >= 0) && !IsLetter(firstpos))
1049 // now find the beginning by looking for a nonletter
1051 while ((firstpos>= 0) && IsLetter(firstpos))
1054 // the above is now pointing to the preceeding non-letter
1058 // so copy characters into theword until we get a nonletter
1059 // note that this can easily exceed lastpos, wich means
1060 // that if used in the middle of a word, the whole word
1063 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1070 LyXParagraph::size_type LyXParagraph::Last() const
1073 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1074 return text.size() + NextAfterFootnote()->Last() + 1;
1075 // the 1 is the symbol
1083 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1085 // > because last is the next unused position, and you can
1086 // use it if you want
1090 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1091 return NextAfterFootnote()
1092 ->ParFromPos(pos - text.size() - 1);
1095 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1096 "position does not exist." << endl;
1103 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1105 // > because last is the next unused position, and you can
1106 // use it if you want
1110 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1111 return NextAfterFootnote()
1112 ->PositionInParFromPos(pos - text.size() - 1);
1116 "ERROR (LyXParagraph::PositionInParFromPos): "
1117 "position does not exist." << endl;
1125 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1126 LyXFont const & font)
1128 // > because last is the next unused position, and you can
1129 // use it if you want
1133 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1134 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1138 lyxerr << "ERROR (LyXParagraph::SetFont): "
1139 "position does not exist." << endl;
1144 // First, reduce font against layout/label font
1145 // Update: The SetCharFont() routine in text2.C already
1146 // reduces font, so we don't need to do that here. (Asger)
1147 // No need to simplify this because it will disappear
1148 // in a new kernel. (Asger)
1149 // Next search font table
1151 FontList::iterator it = lower_bound(fontlist.begin(),
1154 unsigned int i = it - fontlist.begin();
1155 bool notfound = it == fontlist.end();
1157 if (!notfound && fontlist[i].font == font)
1160 bool begin = pos == 0 || notfound ||
1161 (i > 0 && fontlist[i-1].pos == pos - 1);
1162 // Is position pos is a beginning of a font block?
1163 bool end = !notfound && fontlist[i].pos == pos;
1164 // Is position pos is the end of a font block?
1165 if (begin && end) { // A single char block
1166 if (i+1 < fontlist.size() &&
1167 fontlist[i+1].font == font) {
1168 // Merge the singleton block with the next block
1169 fontlist.erase(fontlist.begin() + i);
1170 if (i > 0 && fontlist[i-1].font == font)
1171 fontlist.erase(fontlist.begin() + i-1);
1172 } else if (i > 0 && fontlist[i-1].font == font) {
1173 // Merge the singleton block with the previous block
1174 fontlist[i-1].pos = pos;
1175 fontlist.erase(fontlist.begin() + i);
1177 fontlist[i].font = font;
1179 if (i > 0 && fontlist[i-1].font == font)
1180 fontlist[i-1].pos = pos;
1182 fontlist.insert(fontlist.begin() + i,
1183 FontTable(pos, font));
1185 fontlist[i].pos = pos - 1;
1186 if (!(i+1 < fontlist.size() &&
1187 fontlist[i+1].font == font))
1188 fontlist.insert(fontlist.begin() + i+1,
1189 FontTable(pos, font));
1190 } else { // The general case. The block is splitted into 3 blocks
1191 fontlist.insert(fontlist.begin() + i,
1192 FontTable(pos - 1, fontlist[i].font));
1193 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1198 // This function is able to hide closed footnotes.
1199 LyXParagraph * LyXParagraph::Next()
1202 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1203 LyXParagraph * tmp = next;
1205 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1207 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1208 return tmp->Next(); /* there can be more than one
1209 footnote in a logical
1212 return next; // This should never happen!
1219 LyXParagraph * LyXParagraph::NextAfterFootnote()
1222 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1223 LyXParagraph * tmp = next;
1224 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1226 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1227 return tmp; /* there can be more than one footnote
1228 in a logical paragraph */
1230 return next; // This should never happen!
1237 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1240 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1241 LyXParagraph * tmp = next;
1242 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1244 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1245 return tmp; /* there can be more than one footnote
1246 in a logical paragraph */
1248 return next; // This should never happen!
1255 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1259 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1261 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1262 tmp = tmp->previous;
1263 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1264 return tmp; /* there can be more than one footnote
1265 in a logical paragraph */
1267 return previous; // This should never happen!
1274 LyXParagraph * LyXParagraph::LastPhysicalPar()
1277 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1280 LyXParagraph * tmp = this;
1282 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1283 tmp = tmp->NextAfterFootnote();
1291 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1294 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1297 LyXParagraph const * tmp = this;
1299 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1300 tmp = tmp->NextAfterFootnote();
1308 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1313 LyXParagraph * tmppar = this;
1317 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1318 tmppar = tmppar->previous;
1330 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1335 LyXParagraph const * tmppar = this;
1339 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1340 tmppar = tmppar->previous;
1352 // This function is able to hide closed footnotes.
1353 LyXParagraph * LyXParagraph::Previous()
1355 LyXParagraph * tmp = previous;
1361 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1362 tmp = tmp->previous;
1364 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1365 tmp = tmp->previous;
1366 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1367 return tmp->next->Previous();
1377 // This function is able to hide closed footnotes.
1378 LyXParagraph const * LyXParagraph::Previous() const
1380 LyXParagraph * tmp = previous;
1385 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1386 tmp = tmp->previous;
1388 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1389 tmp = tmp->previous;
1390 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1391 return tmp->next->Previous();
1401 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1402 LyXParagraph::size_type pos,
1405 size_type i, j, pos_end, pos_first;
1406 // create a new paragraph
1407 LyXParagraph * par = ParFromPos(pos);
1408 LyXParagraph * firstpar = FirstPhysicalPar();
1410 LyXParagraph * tmp = new LyXParagraph(par);
1413 tmp->footnoteflag = footnoteflag;
1414 tmp->footnotekind = footnotekind;
1416 // this is an idea for a more userfriendly layout handling, I will
1417 // see what the users say
1419 // layout stays the same with latex-environments
1421 tmp->SetOnlyLayout(bparams, firstpar->layout);
1422 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1425 if (Last() > pos || !Last() || flag == 2) {
1426 tmp->SetOnlyLayout(bparams, firstpar->layout);
1427 tmp->align = firstpar->align;
1428 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1430 tmp->line_bottom = firstpar->line_bottom;
1431 firstpar->line_bottom = false;
1432 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1433 firstpar->pagebreak_bottom = false;
1434 tmp->added_space_bottom = firstpar->added_space_bottom;
1435 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1437 tmp->depth = firstpar->depth;
1438 tmp->noindent = firstpar->noindent;
1440 // copy everything behind the break-position
1441 // to the new paragraph
1443 while (ParFromPos(pos_first) != par)
1446 pos_end = pos_first + par->text.size() - 1;
1448 for (i = j = pos; i <= pos_end; ++i) {
1449 par->CutIntoMinibuffer(bparams, i - pos_first);
1450 if (tmp->InsertFromMinibuffer(j - pos))
1453 tmp->text.resize(tmp->text.size());
1454 for (i = pos_end; i >= pos; --i)
1455 par->Erase(i - pos_first);
1457 par->text.resize(par->text.size());
1460 // just an idea of me
1462 tmp->line_top = firstpar->line_top;
1463 tmp->pagebreak_top = firstpar->pagebreak_top;
1464 tmp->added_space_top = firstpar->added_space_top;
1465 tmp->bibkey = firstpar->bibkey;
1467 // layout stays the same with latex-environments
1469 firstpar->SetOnlyLayout(bparams, tmp->layout);
1470 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1471 firstpar->depth = tmp->depth;
1477 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1479 par = par->FirstPhysicalPar();
1481 footnoteflag = par->footnoteflag;
1482 footnotekind = par->footnotekind;
1484 layout = par->layout;
1485 align = par-> align;
1486 SetLabelWidthString(par->labelwidthstring);
1488 line_bottom = par->line_bottom;
1489 pagebreak_bottom = par->pagebreak_bottom;
1490 added_space_bottom = par->added_space_bottom;
1492 line_top = par->line_top;
1493 pagebreak_top = par->pagebreak_top;
1494 added_space_top = par->added_space_top;
1496 spacing = par->spacing;
1498 pextra_type = par->pextra_type;
1499 pextra_width = par->pextra_width;
1500 pextra_widthp = par->pextra_widthp;
1501 pextra_alignment = par->pextra_alignment;
1502 pextra_hfill = par->pextra_hfill;
1503 pextra_start_minipage = par->pextra_start_minipage;
1505 noindent = par->noindent;
1511 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1513 LyXParagraph * tmppar = this;
1516 && tmppar->previous->footnoteflag ==
1517 LyXParagraph::CLOSED_FOOTNOTE)
1518 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1519 tmppar = tmppar->previous;
1522 return this; // This should never happen!
1529 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1531 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1535 if (!IsDummy() && !table){
1537 && (IsNewline(0) || IsLineSeparator(0))){
1546 LyXParagraph * LyXParagraph::Clone() const
1548 // create a new paragraph
1549 LyXParagraph * result = new LyXParagraph;
1551 result->MakeSameLayout(this);
1553 // this is because of the dummy layout of the paragraphs that
1555 result->layout = layout;
1558 /* table stuff -- begin*/
1560 result->table = table->Clone();
1563 /* table stuff -- end*/
1565 result->inset_owner = inset_owner;
1568 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1571 // copy everything behind the break-position to the new paragraph
1573 result->text = text;
1574 result->fontlist = fontlist;
1575 result->insetlist = insetlist;
1576 for (InsetList::iterator it = result->insetlist.begin();
1577 it != result->insetlist.end(); ++it)
1578 (*it).inset = (*it).inset->Clone();
1583 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1585 par = par->FirstPhysicalPar();
1589 par->footnoteflag == footnoteflag &&
1590 par->footnotekind == footnotekind &&
1592 par->layout == layout &&
1594 par->align == align &&
1596 par->line_bottom == line_bottom &&
1597 par->pagebreak_bottom == pagebreak_bottom &&
1598 par->added_space_bottom == added_space_bottom &&
1600 par->line_top == line_top &&
1601 par->pagebreak_top == pagebreak_top &&
1602 par->added_space_top == added_space_top &&
1604 par->spacing == spacing &&
1606 par->pextra_type == pextra_type &&
1607 par->pextra_width == pextra_width &&
1608 par->pextra_widthp == pextra_widthp &&
1609 par->pextra_alignment == pextra_alignment &&
1610 par->pextra_hfill == pextra_hfill &&
1611 par->pextra_start_minipage == pextra_start_minipage &&
1613 par->table == table && // what means: NO TABLE AT ALL
1616 par->noindent == noindent &&
1617 par->depth == depth);
1621 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1622 LyXParagraph::size_type pos)
1624 // create a new paragraph
1625 LyXParagraph * par = ParFromPos(pos);
1627 LyXParagraph * tmp = new LyXParagraph(par);
1629 tmp->MakeSameLayout(par);
1631 // When can pos < Last()?
1632 // I guess pos == Last() is possible.
1634 // copy everything behind the break-position to the new
1636 size_type pos_first = 0;
1637 while (ParFromPos(pos_first) != par)
1639 size_type pos_end = pos_first + par->text.size() - 1;
1642 for (i = j = pos; i <= pos_end; ++i) {
1643 par->CutIntoMinibuffer(bparams, i - pos_first);
1644 if (tmp->InsertFromMinibuffer(j - pos))
1647 tmp->text.resize(tmp->text.size());
1648 for (size_type i = pos_end; i >= pos; --i)
1649 par->Erase(i - pos_first);
1651 par->text.resize(par->text.size());
1656 // Be carefull, this does not make any check at all.
1657 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1659 // copy the next paragraph to this one
1660 LyXParagraph * the_next = Next();
1662 LyXParagraph * firstpar = FirstPhysicalPar();
1664 // first the DTP-stuff
1665 firstpar->line_bottom = the_next->line_bottom;
1666 firstpar->added_space_bottom = the_next->added_space_bottom;
1667 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1669 size_type pos_end = the_next->text.size() - 1;
1670 size_type pos_insert = Last();
1672 // ok, now copy the paragraph
1674 for (i = j = 0; i <= pos_end; ++i) {
1675 the_next->CutIntoMinibuffer(bparams, i);
1676 if (InsertFromMinibuffer(pos_insert + j))
1680 // delete the next paragraph
1681 LyXParagraph * ppar = the_next->previous;
1682 LyXParagraph * npar = the_next->next;
1689 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1691 LyXParagraph * par = ParFromPos(pos);
1693 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1694 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1700 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1702 LyXParagraph * par = ParFromPos(pos);
1704 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1705 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1711 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1713 LyXParagraph const * par = this;
1714 int par_depth = GetDepth();
1716 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1718 textclasslist.Style(bparams.textclass,
1719 layout).endlabeltype;
1720 if (endlabeltype != END_LABEL_NO_LABEL) {
1721 LyXParagraph const * last = this;
1722 if( footnoteflag == NO_FOOTNOTE)
1723 last = LastPhysicalPar();
1724 else if (next->footnoteflag == NO_FOOTNOTE)
1725 return endlabeltype;
1727 if (!last || !last->next)
1728 return endlabeltype;
1730 int next_depth = last->next->GetDepth();
1731 if (par_depth > next_depth ||
1732 (par_depth == next_depth && layout != last->next->GetLayout() ))
1733 return endlabeltype;
1738 par = par->DepthHook(par_depth - 1);
1740 par_depth = par->GetDepth();
1742 return END_LABEL_NO_LABEL;
1746 LyXTextClass::size_type LyXParagraph::GetLayout() const
1748 return FirstPhysicalPar()->layout;
1752 char LyXParagraph::GetDepth() const
1754 return FirstPhysicalPar()->depth;
1758 char LyXParagraph::GetAlign() const
1760 return FirstPhysicalPar()->align;
1764 string LyXParagraph::GetLabelstring() const
1766 return FirstPhysicalPar()->labelstring;
1770 int LyXParagraph::GetFirstCounter(int i) const
1772 return FirstPhysicalPar()->counter_[i];
1776 // the next two functions are for the manual labels
1777 string LyXParagraph::GetLabelWidthString() const
1779 if (!FirstPhysicalPar()->labelwidthstring.empty())
1780 return FirstPhysicalPar()->labelwidthstring;
1782 return _("Senseless with this layout!");
1786 void LyXParagraph::SetLabelWidthString(string const & s)
1788 LyXParagraph * par = FirstPhysicalPar();
1790 par->labelwidthstring = s;
1794 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1795 LyXTextClass::size_type new_layout)
1797 LyXParagraph * par = FirstPhysicalPar();
1798 LyXParagraph * ppar = 0;
1799 LyXParagraph * npar = 0;
1801 par->layout = new_layout;
1803 /* table stuff -- begin*/
1806 /* table stuff -- end*/
1808 if (par->pextra_type == PEXTRA_NONE) {
1809 if (par->Previous()) {
1810 ppar = par->Previous()->FirstPhysicalPar();
1813 && (ppar->depth > par->depth))
1814 ppar = ppar->Previous()->FirstPhysicalPar();
1817 npar = par->Next()->NextAfterFootnote();
1820 && (npar->depth > par->depth))
1821 npar = npar->Next()->NextAfterFootnote();
1823 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1825 p1 = ppar->pextra_width,
1826 p2 = ppar->pextra_widthp;
1827 ppar->SetPExtraType(bparams, ppar->pextra_type,
1828 p1.c_str(), p2.c_str());
1830 if ((par->pextra_type == PEXTRA_NONE) &&
1831 npar && (npar->pextra_type != PEXTRA_NONE)) {
1833 p1 = npar->pextra_width,
1834 p2 = npar->pextra_widthp;
1835 npar->SetPExtraType(bparams, npar->pextra_type,
1836 p1.c_str(), p2.c_str());
1842 void LyXParagraph::SetLayout(BufferParams const & bparams,
1843 LyXTextClass::size_type new_layout)
1846 * par = FirstPhysicalPar(),
1850 par->layout = new_layout;
1851 par->labelwidthstring.erase();
1852 par->align = LYX_ALIGN_LAYOUT;
1853 par->added_space_top = VSpace(VSpace::NONE);
1854 par->added_space_bottom = VSpace(VSpace::NONE);
1855 par->spacing.set(Spacing::Default);
1858 /* table stuff -- begin*/
1861 /* table stuff -- end*/
1863 if (par->pextra_type == PEXTRA_NONE) {
1864 if (par->Previous()) {
1865 ppar = par->Previous()->FirstPhysicalPar();
1868 && (ppar->depth > par->depth))
1869 ppar = ppar->Previous()->FirstPhysicalPar();
1872 npar = par->Next()->NextAfterFootnote();
1875 && (npar->depth > par->depth))
1876 npar = npar->Next()->NextAfterFootnote();
1878 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1880 p1 = ppar->pextra_width,
1881 p2 = ppar->pextra_widthp;
1882 ppar->SetPExtraType(bparams, ppar->pextra_type,
1883 p1.c_str(), p2.c_str());
1885 if ((par->pextra_type == PEXTRA_NONE) &&
1886 npar && (npar->pextra_type != PEXTRA_NONE)) {
1888 p1 = npar->pextra_width,
1889 p2 = npar->pextra_widthp;
1890 npar->SetPExtraType(bparams, npar->pextra_type,
1891 p1.c_str(), p2.c_str());
1897 // if the layout of a paragraph contains a manual label, the beginning of the
1898 // main body is the beginning of the second word. This is what the par-
1899 // function returns. If the layout does not contain a label, the main
1900 // body always starts with position 0. This differentiation is necessary,
1901 // because there cannot be a newline or a blank <= the beginning of the
1902 // main body in TeX.
1904 int LyXParagraph::BeginningOfMainBody() const
1906 if (FirstPhysicalPar() != this)
1909 // Unroll the first two cycles of the loop
1910 // and remember the previous character to
1911 // remove unnecessary GetChar() calls
1914 && GetChar(i) != LyXParagraph::META_NEWLINE
1917 char previous_char = 0, temp = 0;
1919 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1920 // Yes, this ^ is supposed to be "= " not "=="
1923 && previous_char != ' '
1924 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1926 previous_char = temp;
1931 if (i == 0 && i == size() &&
1932 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1933 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1934 ++i; /* the cursor should not jump
1935 * to the main body if there
1941 LyXParagraph * LyXParagraph::DepthHook(int deth)
1943 LyXParagraph * newpar = this;
1948 newpar = newpar->FirstPhysicalPar()->Previous();
1949 } while (newpar && newpar->GetDepth() > deth
1950 && newpar->footnoteflag == footnoteflag);
1953 if (Previous() || GetDepth())
1954 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1958 return newpar->FirstPhysicalPar();
1962 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1964 LyXParagraph const * newpar = this;
1969 newpar = newpar->FirstPhysicalPar()->Previous();
1970 } while (newpar && newpar->GetDepth() > deth
1971 && newpar->footnoteflag == footnoteflag);
1974 if (Previous() || GetDepth())
1975 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1979 return newpar->FirstPhysicalPar();
1983 int LyXParagraph::AutoDeleteInsets()
1986 InsetList::size_type index = 0;
1987 while (index < insetlist.size()) {
1988 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1989 Erase(insetlist[index].pos);
1990 // Erase() calls to insetlist.erase(&insetlist[index])
1991 // so index shouldn't be increased.
2000 LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2002 InsetList::iterator it = lower_bound(insetlist.begin(),
2005 return inset_iterator(it);
2009 // returns -1 if inset not found
2010 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2013 // We could use lower_bound here too, we just need to add
2014 // the approp. operator() to matchIT (and change the name
2015 // of that struct). Code would then be:
2016 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2018 // inset, matchIT());
2019 // if ((*cit).inset == inset) {
2020 // return (*cit).pos;
2022 for (InsetList::const_iterator cit = insetlist.begin();
2023 cit != insetlist.end(); ++cit) {
2024 if ((*cit).inset == inset) {
2028 // Think about footnotes.
2029 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2030 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2032 NextAfterFootnote()->GetPositionOfInset(inset);
2034 return text.size() + 1 + further;
2040 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2041 BufferParams const & bparams,
2042 ostream & os, TexRow & texrow,
2045 TexRow & foot_texrow,
2048 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2049 LyXLayout const & style =
2050 textclasslist.Style(bparams.textclass,
2053 bool further_blank_line = false;
2055 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2057 if (start_of_appendix) {
2058 os << "\\appendix\n";
2062 if (!spacing.isDefault()
2063 && (!Previous() || !Previous()->HasSameLayout(this))) {
2064 os << spacing.writeEnvirBegin() << "\n";
2068 if (tex_code_break_column && style.isCommand()){
2073 if (pagebreak_top) {
2075 further_blank_line = true;
2077 if (added_space_top.kind() != VSpace::NONE) {
2078 os << added_space_top.asLatexCommand(bparams);
2079 further_blank_line = true;
2083 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2084 << "\\vspace{-1\\parskip}";
2085 further_blank_line = true;
2088 if (further_blank_line){
2093 Language const * language = getParLanguage(bparams);
2094 Language const * doc_language = bparams.language_info;
2095 if (language != doc_language &&
2096 (!previous || previous->getParLanguage(bparams) != language)) {
2097 os << subst(lyxrc.language_command_begin, "$$lang",
2103 switch (style.latextype) {
2106 << style.latexname()
2107 << style.latexparam();
2109 case LATEX_ITEM_ENVIRONMENT:
2111 bibkey->Latex(buf, os, false, false);
2115 case LATEX_LIST_ENVIRONMENT:
2122 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2125 // Spit out footnotes
2126 LyXParagraph * par = next;
2127 if (lyxrc.rtl_support) {
2128 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2129 && next->footnoteflag != footnoteflag) {
2130 LyXParagraph * p = 0;
2131 bool is_rtl = (size() > 0)
2132 ? GetFontSettings(bparams,
2133 size()-1).isRightToLeft()
2134 : language->RightToLeft();
2135 if ( (p = NextAfterFootnote()) != 0 &&
2137 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2138 is_rtl = getParLanguage(bparams)->RightToLeft();
2139 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2140 && par->footnoteflag != footnoteflag) {
2141 par = par->TeXFootnote(buf, bparams,
2143 foot_texrow, foot_count,
2145 par->SimpleTeXOnePar(buf, bparams,
2146 os, texrow, moving_arg);
2147 is_rtl = (par->size() > 0)
2148 ? par->GetFontSettings(bparams,
2149 par->size()-1).isRightToLeft()
2150 : language->RightToLeft();
2152 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2153 (p = par->NextAfterFootnote()) != 0 &&
2155 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2156 is_rtl = language->RightToLeft();
2161 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2162 && par->footnoteflag != footnoteflag) {
2163 par = par->TeXFootnote(buf, bparams,
2165 foot, foot_texrow, foot_count,
2167 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2173 // Make sure that \\par is done with the font of the last
2174 // character if this has another size as the default.
2175 // This is necessary because LaTeX (and LyX on the screen)
2176 // calculates the space between the baselines according
2177 // to this font. (Matthias)
2178 LyXFont font = getFont(bparams, Last() - 1);
2180 if (style.resfont.size() != font.size()) {
2186 } else if (textclasslist.Style(bparams.textclass,
2187 GetLayout()).isCommand()) {
2188 if (style.resfont.size() != font.size()) {
2194 } else if (style.resfont.size() != font.size()){
2195 os << "{\\" << font.latexSize() << " \\par}";
2198 if (language != doc_language &&
2200 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2201 || par->getParLanguage(bparams) != language)) {
2203 << subst(lyxrc.language_command_end, "$$lang",
2204 doc_language->lang());
2207 switch (style.latextype) {
2208 case LATEX_ITEM_ENVIRONMENT:
2209 case LATEX_LIST_ENVIRONMENT:
2210 if (par && (depth < par->depth)) {
2215 case LATEX_ENVIRONMENT:
2216 // if its the last paragraph of the current environment
2217 // skip it otherwise fall through
2219 && (par->layout != layout
2220 || par->depth != depth
2221 || par->pextra_type != pextra_type))
2224 // we don't need it for the last paragraph!!!
2225 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2226 && footnotekind != LyXParagraph::FOOTNOTE
2227 && footnotekind != LyXParagraph::MARGIN
2231 // don't insert this if we would be adding it
2232 // before or after a table in a float. This
2233 // little trick is needed in order to allow
2234 // use of tables in \subfigures or \subtables.
2240 further_blank_line = false;
2242 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2243 further_blank_line = true;
2246 if (added_space_bottom.kind() != VSpace::NONE) {
2247 os << added_space_bottom.asLatexCommand(bparams);
2248 further_blank_line = true;
2251 if (pagebreak_bottom) {
2253 further_blank_line = true;
2256 if (further_blank_line){
2261 if (!spacing.isDefault()
2262 && (!par || !par->HasSameLayout(this))) {
2263 os << spacing.writeEnvirEnd() << "\n";
2267 // we don't need it for the last paragraph!!!
2268 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2269 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2274 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2279 // This one spits out the text of the paragraph
2280 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2281 BufferParams const & bparams,
2282 ostream & os, TexRow & texrow,
2285 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2289 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2292 bool return_value = false;
2294 LyXLayout const & style =
2295 textclasslist.Style(bparams.textclass,
2297 LyXFont basefont, last_font;
2299 // Maybe we have to create a optional argument.
2300 size_type main_body;
2301 if (style.labeltype != LABEL_MANUAL)
2304 main_body = BeginningOfMainBody();
2306 if (main_body > 0) {
2308 basefont = getFont(bparams, -2); // Get label font
2310 basefont = getFont(bparams, -1); // Get layout font
2318 if (style.isCommand()) {
2321 } else if (align != LYX_ALIGN_LAYOUT) {
2324 return_value = true;
2328 moving_arg |= style.needprotect;
2330 // Which font is currently active?
2331 LyXFont running_font(basefont);
2332 // Do we have an open font change?
2333 bool open_font = false;
2335 texrow.start(this, 0);
2337 for (size_type i = 0; i < size(); ++i) {
2339 // First char in paragraph or after label?
2340 if (i == main_body && !IsDummy()) {
2341 if (main_body > 0) {
2343 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2346 basefont = getFont(bparams, -1); // Now use the layout font
2347 running_font = basefont;
2351 if (style.isCommand()) {
2354 } else if (align != LYX_ALIGN_LAYOUT) {
2357 return_value = true;
2361 os << "\\noindent ";
2365 case LYX_ALIGN_NONE:
2366 case LYX_ALIGN_BLOCK:
2367 case LYX_ALIGN_LAYOUT:
2368 case LYX_ALIGN_SPECIAL:
2370 case LYX_ALIGN_LEFT:
2371 if (getParLanguage(bparams)->lang() != "hebrew") {
2372 os << "\\raggedright ";
2375 os << "\\raggedleft ";
2379 case LYX_ALIGN_RIGHT:
2380 if (getParLanguage(bparams)->lang() != "hebrew") {
2381 os << "\\raggedleft ";
2384 os << "\\raggedright ";
2388 case LYX_ALIGN_CENTER:
2389 os << "\\centering ";
2397 // Fully instantiated font
2398 LyXFont font = getFont(bparams, i);
2399 LyXParagraph * p = 0;
2400 if (i == 0 && previous &&
2401 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2402 (p = PreviousBeforeFootnote()) != 0)
2403 last_font = p->getFont(bparams, p->size()-1);
2405 last_font = running_font;
2407 // Spaces at end of font change are simulated to be
2408 // outside font change, i.e. we write "\textXX{text} "
2409 // rather than "\textXX{text }". (Asger)
2410 if (open_font && c == ' ' && i <= size() - 2
2411 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2412 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2413 font = getFont(bparams, i + 1);
2415 // We end font definition before blanks
2416 if (!font.equalExceptLatex(running_font) && open_font) {
2417 column += running_font.latexWriteEndChanges(os,
2419 (i == main_body-1) ? basefont : font);
2420 running_font = basefont;
2424 // Blanks are printed before start of fontswitch
2426 // Do not print the separation of the optional argument
2427 if (i != main_body - 1) {
2428 SimpleTeXBlanks(os, texrow, i,
2429 column, font, style);
2433 // Do we need to change font?
2434 if (!font.equalExceptLatex(running_font)
2435 && i != main_body-1) {
2436 column += font.latexWriteStartChanges(os, basefont,
2438 running_font = font;
2442 if (c == LyXParagraph::META_NEWLINE) {
2443 // newlines are handled differently here than
2444 // the default in SimpleTeXSpecialChars().
2445 if (!style.newline_allowed
2446 || font.latex() == LyXFont::ON) {
2450 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2453 basefont = getFont(bparams, -1);
2454 running_font = basefont;
2455 if (font.family() ==
2456 LyXFont::TYPEWRITER_FAMILY) {
2464 texrow.start(this, i + 1);
2467 SimpleTeXSpecialChars(buf, bparams,
2468 os, texrow, moving_arg,
2469 font, running_font, basefont,
2470 open_font, style, i, column, c);
2474 // If we have an open font definition, we have to close it
2476 LyXParagraph * p = 0;
2477 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2478 && (p = NextAfterFootnote()) != 0)
2479 running_font.latexWriteEndChanges(os, basefont,
2480 p->getFont(bparams, 0));
2482 running_font.latexWriteEndChanges(os, basefont, basefont);
2485 // Needed if there is an optional argument but no contents.
2486 if (main_body > 0 && main_body == size()) {
2488 return_value = false;
2491 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2492 return return_value;
2496 // This one spits out the text of a table paragraph
2497 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2498 BufferParams const & bparams,
2499 ostream & os, TexRow & texrow)
2501 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2503 bool return_value = false;
2505 LyXLayout const & style =
2506 textclasslist.Style(bparams.textclass, GetLayout());
2509 if (!IsDummy()) { // it is dummy if it is in a float!!!
2510 if (style.isCommand()) {
2513 } else if (align != LYX_ALIGN_LAYOUT) {
2516 return_value = true;
2519 os << "\\noindent ";
2523 case LYX_ALIGN_NONE:
2524 case LYX_ALIGN_BLOCK:
2525 case LYX_ALIGN_LAYOUT:
2526 case LYX_ALIGN_SPECIAL: break;
2527 case LYX_ALIGN_LEFT:
2528 os << "\\raggedright ";
2531 case LYX_ALIGN_RIGHT:
2532 os << "\\raggedleft ";
2535 case LYX_ALIGN_CENTER:
2536 os << "\\centering ";
2542 LyXFont basefont = getFont(bparams, -1); // Get layout font
2543 // Which font is currently active?
2544 LyXFont running_font = basefont;
2546 // Do we have an open font change?
2547 bool open_font = false;
2548 int current_cell_number = -1;
2549 int tmp = table->TexEndOfCell(os, current_cell_number);
2550 for (; tmp > 0 ; --tmp)
2553 texrow.start(this, 0);
2555 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2556 bool first_in_cell = true;
2558 for (size_type i = 0; i < size(); ++i) {
2559 char c = GetChar(i);
2560 if (table->IsContRow(current_cell_number + 1)) {
2561 if (c == LyXParagraph::META_NEWLINE)
2562 ++current_cell_number;
2567 if (first_in_cell && is_rtl) {
2570 first_in_cell = false;
2573 // Fully instantiated font
2574 LyXFont font = getFont(bparams, i);
2575 last_font = running_font;
2577 // Spaces at end of font change are simulated to be
2578 // outside font change.
2579 // i.e. we write "\textXX{text} " rather than
2580 // "\textXX{text }". (Asger)
2581 if (open_font && c == ' ' && i <= size() - 2
2582 && getFont(bparams, i + 1) != running_font
2583 && getFont(bparams, i + 1) != font) {
2584 font = getFont(bparams, i + 1);
2587 // We end font definition before blanks
2588 if (font != running_font && open_font) {
2589 column += running_font.latexWriteEndChanges(os,
2592 running_font = basefont;
2595 // Blanks are printed before start of fontswitch
2597 SimpleTeXBlanks(os, texrow, i, column, font, style);
2599 // Do we need to change font?
2600 if (font != running_font) {
2601 column += font.latexWriteStartChanges(os, basefont,
2603 running_font = font;
2606 // Do we need to turn on LaTeX mode?
2607 if (font.latex() != running_font.latex()) {
2608 if (font.latex() == LyXFont::ON
2609 && style.needprotect) {
2614 if (c == LyXParagraph::META_NEWLINE) {
2615 // special case for inside a table
2616 // different from default case in
2617 // SimpleTeXSpecialChars()
2619 column += running_font
2620 .latexWriteEndChanges(os, basefont,
2624 basefont = getFont(bparams, -1);
2625 running_font = basefont;
2626 ++current_cell_number;
2627 if (table->CellHasContRow(current_cell_number) >= 0) {
2628 TeXContTableRows(buf, bparams, os, i + 1,
2629 current_cell_number,
2632 if (is_rtl && !first_in_cell) {
2634 first_in_cell = true;
2637 // if this cell follow only ContRows till end don't
2638 // put the EndOfCell because it is put after the
2640 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2641 --current_cell_number;
2644 int tmp = table->TexEndOfCell(os,
2645 current_cell_number);
2648 } else if (tmp < 0) {
2654 texrow.start(this, i + 1);
2656 SimpleTeXSpecialChars(buf, bparams,
2658 font, running_font, basefont,
2659 open_font, style, i, column, c);
2663 // If we have an open font definition, we have to close it
2665 running_font.latexWriteEndChanges(os, basefont, basefont);
2667 ++current_cell_number;
2668 if (is_rtl && !first_in_cell)
2670 tmp = table->TexEndOfCell(os, current_cell_number);
2671 for (; tmp > 0; --tmp)
2673 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2674 return return_value;
2678 // This one spits out the text off ContRows in tables
2679 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2680 BufferParams const & bparams,
2682 LyXParagraph::size_type i,
2683 int current_cell_number,
2684 int & column, TexRow & texrow)
2686 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2690 bool return_value = false;
2691 LyXLayout const & style =
2692 textclasslist.Style(bparams.textclass,
2694 LyXFont basefont = getFont(bparams, -1); // Get layout font
2696 // Which font is currently active?
2697 LyXFont running_font = basefont;
2698 // Do we have an open font change?
2699 bool open_font = false;
2701 size_type lastpos = i;
2702 int cell = table->CellHasContRow(current_cell_number);
2703 ++current_cell_number;
2706 // first find the right position
2708 for (; (i < size()) && (current_cell_number<cell); ++i) {
2710 if (c == LyXParagraph::META_NEWLINE)
2711 ++current_cell_number;
2715 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2719 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2724 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2728 // Fully instantiated font
2729 LyXFont font = getFont(bparams, i);
2730 last_font = running_font;
2732 // Spaces at end of font change are simulated to
2733 // be outside font change. i.e. we write
2734 // "\textXX{text} " rather than "\textXX{text }".
2736 if (open_font && c == ' ' && i <= size() - 2
2737 && getFont(bparams, i + 1) != running_font
2738 && getFont(bparams, i + 1) != font) {
2739 font = getFont(bparams, i + 1);
2742 // We end font definition before blanks
2743 if (font != running_font && open_font) {
2744 column += running_font.latexWriteEndChanges(os, basefont, font);
2745 running_font = basefont;
2748 // Blanks are printed before start of fontswitch
2750 SimpleTeXBlanks(os, texrow, i,
2751 column, font, style);
2753 // Do we need to change font?
2754 if (font != running_font) {
2756 font.latexWriteStartChanges(os,
2759 running_font = font;
2762 // Do we need to turn on LaTeX mode?
2763 if (font.latex() != running_font.latex()) {
2764 if (font.latex() == LyXFont::ON
2765 && style.needprotect) {
2770 SimpleTeXSpecialChars(buf, bparams,
2771 os, texrow, false, font,
2772 running_font, basefont,
2773 open_font, style, i, column, c);
2775 // If we have an open font definition, we have to close it
2777 running_font.latexWriteEndChanges(os, basefont,
2781 basefont = getFont(bparams, -1);
2782 running_font = basefont;
2783 cell = table->CellHasContRow(current_cell_number);
2785 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2786 return return_value;
2790 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2792 bool retval = false;
2794 case LyXParagraph::META_HFILL:
2795 sgml_string.erase();
2797 case LyXParagraph::META_NEWLINE:
2801 sgml_string = "&";
2804 sgml_string = "<";
2807 sgml_string = ">";
2810 sgml_string = "$";
2813 sgml_string = "#";
2816 sgml_string = "%";
2819 sgml_string = "[";
2822 sgml_string = "]";
2825 sgml_string = "{";
2828 sgml_string = "}";
2831 sgml_string = "˜";
2834 sgml_string = """;
2837 sgml_string = "\";
2843 case '\0': // Ignore :-)
2844 sgml_string.erase();
2854 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
2855 ostream & os, string & extra,
2856 int & desc_on, int depth)
2858 BufferParams const & bparams = buffer->params;
2860 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2862 LyXFont font1, font2;
2865 size_type main_body;
2866 bool emph_flag = false;
2868 LyXLayout const & style =
2869 textclasslist.Style(bparams.textclass,
2872 if (style.labeltype != LABEL_MANUAL)
2875 main_body = BeginningOfMainBody();
2877 // Gets paragraph main font.
2879 font1 = style.labelfont;
2883 int char_line_count = depth;
2884 os << newlineAndDepth(depth);
2885 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2886 os << "<INFORMALTABLE>"
2887 << newlineAndDepth(++depth);
2889 int current_cell_number = -1;
2890 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2892 // Parsing main loop.
2893 for (size_type i = 0; i < size(); ++i) {
2895 if (table->IsContRow(current_cell_number+1)) {
2896 if (c == LyXParagraph::META_NEWLINE)
2897 ++current_cell_number;
2902 // Fully instantiated font
2903 font2 = getFont(bparams, i);
2905 // Handle <emphasis> tag.
2906 if (font1.emph() != font2.emph() && i) {
2907 if (font2.emph() == LyXFont::ON) {
2910 } else if (emph_flag) {
2911 os << "</emphasis>";
2915 if (c == LyXParagraph::META_NEWLINE) {
2916 // We have only to control for emphasis open here!
2918 os << "</emphasis>";
2921 font1 = font2 = getFont(bparams, -1);
2922 ++current_cell_number;
2923 if (table->CellHasContRow(current_cell_number) >= 0) {
2924 DocBookContTableRows(buffer,
2925 os, extra, desc_on, i + 1,
2926 current_cell_number,
2929 // if this cell follow only ContRows till end don't
2930 // put the EndOfCell because it is put after the
2932 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2933 --current_cell_number;
2936 tmp = table->DocBookEndOfCell(os,
2937 current_cell_number,
2942 } else if (c == LyXParagraph::META_INSET) {
2943 inset = GetInset(i);
2945 std::ostringstream ost;
2946 inset->DocBook(buffer, ost);
2947 string tmp_out = ost.str().c_str();
2950 inset->DocBook(buffer, ost);
2952 char * ctmp = ost.str();
2953 string tmp_out(ctmp);
2957 // This code needs some explanation:
2958 // Two insets are treated specially
2959 // label if it is the first element in a
2960 // command paragraph
2962 // graphics inside tables or figure floats
2964 // title (the equivalente in latex for this
2966 // and title should come first
2969 if(desc_on != 3 || i != 0) {
2970 if(tmp_out[0] == '@') {
2972 extra += frontStrip(tmp_out,
2975 os << frontStrip(tmp_out,
2980 } else if (font2.latex() == LyXFont::ON) {
2981 // "TeX"-Mode on == > SGML-Mode on.
2987 if (linuxDocConvertChar(c, sgml_string)
2988 && !style.free_spacing) {
2989 // in freespacing mode, spaces are
2990 // non-breaking characters
2995 << "</term><listitem><para>";
3007 // Needed if there is an optional argument but no contents.
3008 if (main_body > 0 && main_body == size()) {
3013 os << "</emphasis>";
3016 ++current_cell_number;
3017 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3018 // Resets description flag correctly.
3021 // <term> not closed...
3025 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3026 os << "</INFORMALTABLE>";
3028 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3033 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3034 ostream & os, string & extra,
3036 LyXParagraph::size_type i,
3037 int current_cell_number, int &column)
3042 BufferParams const & bparams = buffer->params;
3044 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3049 //string emph = "emphasis";
3050 bool emph_flag = false;
3051 int char_line_count = 0;
3053 LyXLayout const & style =
3054 textclasslist.Style(bparams.textclass,
3057 size_type main_body;
3058 if (style.labeltype != LABEL_MANUAL)
3061 main_body = BeginningOfMainBody();
3063 // Gets paragraph main font.
3066 font1 = style.labelfont;
3070 size_type lastpos = i;
3071 int cell = table->CellHasContRow(current_cell_number);
3072 ++current_cell_number;
3074 // first find the right position
3076 for (; i < size() && current_cell_number < cell; ++i) {
3078 if (c == LyXParagraph::META_NEWLINE)
3079 ++current_cell_number;
3083 // I don't know how to handle this so I comment it
3084 // for the moment (Jug)
3085 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3086 // file += " \\\\\n";
3089 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3094 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3098 // Fully instantiated font
3099 font2 = getFont(bparams, i);
3101 // Handle <emphasis> tag.
3102 if (font1.emph() != font2.emph() && i) {
3103 if (font2.emph() == LyXFont::ON) {
3106 } else if (emph_flag) {
3107 os << "</emphasis>";
3111 if (c == LyXParagraph::META_INSET) {
3112 inset = GetInset(i);
3114 std::ostringstream ost;
3115 inset->DocBook(buffer, ost);
3116 string tmp_out = ost.str().c_str();
3119 inset->DocBook(buffer, ost);
3121 char * ctmp = ost.str();
3122 string tmp_out(ctmp);
3126 // This code needs some explanation:
3127 // Two insets are treated specially
3128 // label if it is the first element in a
3129 // command paragraph
3131 // graphics inside tables or figure floats
3132 // can't go on title (the equivalente in
3133 // latex for this case is caption and title
3134 // should come first
3137 if(desc_on != 3 || i != 0) {
3138 if(tmp_out[0] == '@') {
3140 extra += frontStrip(tmp_out, '@');
3142 os << frontStrip(tmp_out, '@');
3146 } else if (font2.latex() == LyXFont::ON) {
3147 // "TeX"-Mode on == > SGML-Mode on.
3153 if (linuxDocConvertChar(c, sgml_string)
3154 && !style.free_spacing) {
3155 // in freespacing mode, spaces are
3156 // non-breaking characters
3161 << "</term><listitem><para>";
3171 // we have only to control for emphasis open here!
3173 os << "</emphasis>";
3176 font1 = font2 = getFont(bparams, -1);
3177 cell = table->CellHasContRow(current_cell_number);
3179 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3183 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3184 LyXParagraph::size_type const i,
3185 int & column, LyXFont const & font,
3186 LyXLayout const & style)
3188 if (column > tex_code_break_column
3190 && GetChar(i - 1) != ' '
3192 // In LaTeX mode, we don't want to
3193 // break lines since some commands
3195 && ! (font.latex() == LyXFont::ON)
3196 // same in FreeSpacing mode
3197 && !style.free_spacing
3198 // In typewriter mode, we want to avoid
3199 // ! . ? : at the end of a line
3200 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3201 && (GetChar(i-1) == '.'
3202 || GetChar(i-1) == '?'
3203 || GetChar(i-1) == ':'
3204 || GetChar(i-1) == '!'))) {
3205 if (tex_code_break_column == 0) {
3206 // in batchmode we need LaTeX to still
3207 // see it as a space not as an extra '\n'
3213 texrow.start(this, i + 1);
3215 } else if (font.latex() == LyXFont::OFF) {
3216 if (style.free_spacing) {
3225 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3226 BufferParams const & bparams,
3227 ostream & os, TexRow & texrow,
3230 LyXFont & running_font,
3233 LyXLayout const & style,
3234 LyXParagraph::size_type & i,
3235 int & column, char const c)
3237 // Two major modes: LaTeX or plain
3238 // Handle here those cases common to both modes
3239 // and then split to handle the two modes separately.
3241 case LyXParagraph::META_INSET: {
3242 Inset * inset = GetInset(i);
3245 int len = os.tellp();
3246 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3247 || inset->LyxCode() == Inset::MATH_CODE
3248 || inset->LyxCode() == Inset::URL_CODE)
3249 && running_font.isRightToLeft()) {
3254 int tmp = inset->Latex(buf, os, moving_arg,
3255 style.free_spacing);
3263 column += os.tellp() - len;
3272 case LyXParagraph::META_NEWLINE:
3274 column += running_font.latexWriteEndChanges(os,
3279 basefont = getFont(bparams, -1);
3280 running_font = basefont;
3283 case LyXParagraph::META_HFILL:
3289 // And now for the special cases within each mode
3290 // Are we in LaTeX mode?
3291 if (font.latex() == LyXFont::ON) {
3292 // at present we only have one option
3293 // but I'll leave it as a switch statement
3294 // so its simpler to extend. (ARRae)
3297 // make sure that we will not print
3298 // error generating chars to the tex
3299 // file. This test would not be needed
3300 // if it were done in the buffer
3308 // Plain mode (i.e. not LaTeX)
3311 os << "\\textbackslash{}";
3315 case '°': case '±': case '²': case '³':
3316 case '×': case '÷': case '¹': case 'ª':
3317 case 'º': case '¬': case 'µ':
3318 if (bparams.inputenc == "latin1") {
3319 os << "\\ensuremath{"
3328 case '|': case '<': case '>':
3329 // In T1 encoding, these characters exist
3330 if (lyxrc.fontenc == "T1") {
3332 //... but we should avoid ligatures
3333 if ((c == '>' || c == '<')
3335 && GetChar(i + 1) == c) {
3336 //os << "\\textcompwordmark{}";
3337 // Jean-Marc, have a look at
3338 // this. IÂ think this works
3346 // Typewriter font also has them
3347 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3351 // Otherwise, we use what LaTeX
3355 os << "\\textless{}";
3359 os << "\\textgreater{}";
3363 os << "\\textbar{}";
3369 case '-': // "--" in Typewriter mode -> "-{}-"
3371 && GetChar(i + 1) == '-'
3372 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3381 os << "\\char`\\\"{}";
3386 if (bparams.inputenc == "default") {
3395 case '%': case '#': case '{':
3402 os << "\\textasciitilde{}";
3407 os << "\\textasciicircum{}";
3411 case '*': case '[': case ']':
3412 // avoid being mistaken for optional arguments
3413 os << '{' << c << '}';
3418 // Blanks are printed before font switching.
3419 // Sure? I am not! (try nice-latex)
3420 // I am sure it's correct. LyX might be smarter
3421 // in the future, but for now, nothing wrong is
3426 /* idea for labels --- begin*/
3430 && font.family() != LyXFont::TYPEWRITER_FAMILY
3431 && GetChar(i + 1) == 'y'
3432 && GetChar(i + 2) == 'X') {
3440 && font.family() != LyXFont::TYPEWRITER_FAMILY
3441 && GetChar(i + 1) == 'e'
3442 && GetChar(i + 2) == 'X') {
3447 // Check for "LaTeX2e"
3450 && font.family() != LyXFont::TYPEWRITER_FAMILY
3451 && GetChar(i + 1) == 'a'
3452 && GetChar(i + 2) == 'T'
3453 && GetChar(i + 3) == 'e'
3454 && GetChar(i + 4) == 'X'
3455 && GetChar(i + 5) == '2'
3456 && GetChar(i + 6) == 'e') {
3461 // Check for "LaTeX"
3464 && font.family() != LyXFont::TYPEWRITER_FAMILY
3465 && GetChar(i + 1) == 'a'
3466 && GetChar(i + 2) == 'T'
3467 && GetChar(i + 3) == 'e'
3468 && GetChar(i + 4) == 'X') {
3472 /* idea for labels --- end*/
3473 } else if (c != '\0') {
3483 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3484 BufferParams const & bparams,
3485 ostream & os, TexRow & texrow,
3487 TexRow & foot_texrow,
3490 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3491 LyXParagraph * par = this;
3494 (par->depth == depth) &&
3495 (par->footnoteflag == footnoteflag)) {
3497 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3498 if (textclasslist.Style(bparams.textclass,
3499 par->layout).isEnvironment()
3500 || par->pextra_type != PEXTRA_NONE) {
3501 par = par->TeXEnvironment(buf, bparams,
3506 par = par->TeXOnePar(buf, bparams,
3512 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3518 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3519 BufferParams const & bparams,
3520 ostream & os, TexRow & texrow,
3522 TexRow & foot_texrow,
3525 bool eindent_open = false;
3526 bool foot_this_level = false;
3527 // flags when footnotetext should be appended to file.
3528 static bool minipage_open = false;
3529 static int minipage_open_depth = 0;
3530 char par_sep = bparams.paragraph_separation;
3532 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3534 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3536 LyXLayout const & style =
3537 textclasslist.Style(bparams.textclass,
3540 if (pextra_type == PEXTRA_INDENT) {
3541 if (!pextra_width.empty()) {
3542 os << "\\begin{LyXParagraphIndent}{"
3543 << pextra_width << "}\n";
3545 //float ib = atof(pextra_widthp.c_str())/100;
3546 // string can't handle floats at present (971109)
3547 // so I'll do a conversion by hand knowing that
3548 // the limits are 0.0 to 1.0. ARRae.
3549 os << "\\begin{LyXParagraphIndent}{";
3550 switch (pextra_widthp.length()) {
3562 os << "\\columnwidth}\n";
3565 eindent_open = true;
3567 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3568 if (pextra_hfill && Previous() &&
3569 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3570 os << "\\hfill{}\n";
3573 if (par_sep == BufferParams::PARSEP_INDENT) {
3574 os << "{\\setlength\\parindent{0pt}\n";
3577 os << "\\begin{minipage}";
3578 switch(pextra_alignment) {
3579 case MINIPAGE_ALIGN_TOP:
3582 case MINIPAGE_ALIGN_MIDDLE:
3585 case MINIPAGE_ALIGN_BOTTOM:
3589 if (!pextra_width.empty()) {
3590 os << '{' << pextra_width << "}\n";
3592 //float ib = atof(par->pextra_width.c_str())/100;
3593 // string can't handle floats at present
3594 // so I'll do a conversion by hand knowing that
3595 // the limits are 0.0 to 1.0. ARRae.
3597 switch (pextra_widthp.length()) {
3609 os << "\\columnwidth}\n";
3612 if (par_sep == BufferParams::PARSEP_INDENT) {
3613 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3616 minipage_open = true;
3617 minipage_open_depth = depth;
3620 #ifdef WITH_WARNINGS
3621 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3622 //I disabled it because it breaks when lists span on several
3625 if (style.isEnvironment()){
3626 if (style.latextype == LATEX_LIST_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 << labelwidthstring << "}\n";
3637 } else if (style.labeltype == LABEL_BIBLIO) {
3639 os << "\\begin{" << style.latexname() << "}{"
3640 << bibitemWidest(current_view->painter())
3642 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3643 #ifdef FANCY_FOOTNOTE_CODE
3644 if (foot_count < 0) {
3645 // flag that footnote[mark][text] should be
3646 // used for any footnotes from now on
3648 foot_this_level = true;
3651 os << "\\begin{" << style.latexname() << '}'
3652 << style.latexparam() << '\n';
3654 os << "\\begin{" << style.latexname() << '}'
3655 << style.latexparam() << '\n';
3658 LyXParagraph * par = this;
3660 par = par->TeXOnePar(buf, bparams,
3662 foot, foot_texrow, foot_count);
3664 if (minipage_open && par && !style.isEnvironment() &&
3665 (par->pextra_type == PEXTRA_MINIPAGE) &&
3666 par->pextra_start_minipage) {
3667 os << "\\end{minipage}\n";
3669 if (par_sep == BufferParams::PARSEP_INDENT) {
3673 minipage_open = false;
3675 if (par && par->depth > depth) {
3676 if (textclasslist.Style(bparams.textclass,
3677 par->layout).isParagraph()
3680 // How to handle this? (Lgb)
3681 //&& !suffixIs(os, "\n\n")
3683 // There should be at least one '\n' already
3684 // but we need there to be two for Standard
3685 // paragraphs that are depth-increment'ed to be
3686 // output correctly. However, tables can
3687 // also be paragraphs so don't adjust them.
3690 // Will it ever harm to have one '\n' too
3691 // many? i.e. that we sometimes will have
3692 // three in a row. (Lgb)
3696 par = par->TeXDeeper(buf, bparams, os, texrow,
3697 foot, foot_texrow, foot_count);
3699 if (par && par->layout == layout && par->depth == depth &&
3700 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3701 if (par->pextra_hfill && par->Previous() &&
3702 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3703 os << "\\hfill{}\n";
3706 if (par_sep == BufferParams::PARSEP_INDENT) {
3707 os << "{\\setlength\\parindent{0pt}\n";
3710 os << "\\begin{minipage}";
3711 switch(par->pextra_alignment) {
3712 case MINIPAGE_ALIGN_TOP:
3715 case MINIPAGE_ALIGN_MIDDLE:
3718 case MINIPAGE_ALIGN_BOTTOM:
3722 if (!par->pextra_width.empty()) {
3723 os << '{' << par->pextra_width << "}\n";
3725 //float ib = atof(par->pextra_widthp.c_str())/100;
3726 // string can't handle floats at present
3727 // so I'll do a conversion by hand knowing that
3728 // the limits are 0.0 to 1.0. ARRae.
3730 switch (par->pextra_widthp.length()) {
3735 os << "0." << par->pextra_widthp;
3738 os << "0.0" << par->pextra_widthp;
3740 os << "\\columnwidth}\n";
3743 if (par_sep == BufferParams::PARSEP_INDENT) {
3744 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3747 minipage_open = true;
3748 minipage_open_depth = par->depth;
3751 && par->layout == layout
3752 && par->depth == depth
3753 && par->pextra_type == pextra_type
3754 && par->footnoteflag == footnoteflag);
3756 if (style.isEnvironment()) {
3757 os << "\\end{" << style.latexname() << '}';
3758 // maybe this should go after the minipage closes?
3759 if (foot_this_level) {
3760 if (foot_count >= 1) {
3761 if (foot_count > 1) {
3762 os << "\\addtocounter{footnote}{-"
3767 texrow += foot_texrow;
3769 foot_texrow.reset();
3774 if (minipage_open && (minipage_open_depth == depth) &&
3775 (!par || par->pextra_start_minipage ||
3776 par->pextra_type != PEXTRA_MINIPAGE)) {
3777 os << "\\end{minipage}\n";
3779 if (par_sep == BufferParams::PARSEP_INDENT) {
3783 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3784 os << "\\medskip\n\n";
3788 minipage_open = false;
3791 os << "\\end{LyXParagraphIndent}\n";
3794 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3795 && par->pextra_hfill)) {
3799 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3800 return par; // ale970302
3805 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3806 BufferParams const & bparams,
3807 ostream & os, TexRow & texrow,
3808 ostream & foot, TexRow & foot_texrow,
3812 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3813 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3814 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3815 "No footnote!" << endl;
3817 LyXParagraph * par = this;
3818 LyXLayout const & style =
3819 textclasslist.Style(bparams.textclass,
3820 previous->GetLayout());
3822 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3823 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3824 "Float other than footnote in command"
3825 " with moving argument is illegal" << endl;
3828 if (footnotekind != LyXParagraph::FOOTNOTE
3829 && footnotekind != LyXParagraph::MARGIN
3832 // How to solve this?
3833 //&& !suffixIs(file, '\n')
3835 // we need to ensure that real floats like tables and figures
3836 // have their \begin{} on a new line otherwise we can get
3837 // incorrect results when using the endfloat.sty package
3838 // especially if two floats follow one another. ARRae 981022
3839 // NOTE: if the file is length 0 it must have just been
3840 // written out so we assume it ended with a '\n'
3842 // As far as I can see there is never any harm in writing
3843 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3848 bool moving_arg = false;
3849 bool need_closing = false;
3850 bool is_rtl = isRightToLeftPar(bparams);
3852 if (is_rtl != parent_is_rtl) {
3857 need_closing = true;
3860 //BufferParams * params = ¤t_view->buffer()->params;
3861 bool footer_in_body = true;
3862 switch (footnotekind) {
3863 case LyXParagraph::FOOTNOTE:
3864 if (style.intitle) {
3865 os << "\\thanks{\n";
3866 footer_in_body = false;
3869 if (foot_count == -1) {
3870 // we're at depth 0 so we can use:
3871 os << "\\footnote{%\n";
3872 footer_in_body = false;
3874 os << "\\footnotemark{}%\n";
3876 // we only need this when there are
3877 // multiple footnotes
3878 os << "\\stepcounter{footnote}";
3880 os << "\\footnotetext{%\n";
3881 foot_texrow.start(this, 0);
3882 foot_texrow.newline();
3887 case LyXParagraph::MARGIN:
3888 os << "\\marginpar{\n";
3890 case LyXParagraph::FIG:
3891 if (pextra_type == PEXTRA_FLOATFLT
3892 && (!pextra_width.empty()
3893 || !pextra_widthp.empty())) {
3894 if (!pextra_width.empty())
3895 os << "\\begin{floatingfigure}{"
3896 << pextra_width << "}\n";
3898 os << "\\begin{floatingfigure}{"
3899 << atoi(pextra_widthp.c_str())/100.0
3900 << "\\textwidth}\n";
3902 os << "\\begin{figure}";
3903 if (!bparams.float_placement.empty()) {
3904 os << '[' << bparams.float_placement << "]\n";
3910 case LyXParagraph::TAB:
3911 os << "\\begin{table}";
3912 if (!bparams.float_placement.empty()) {
3913 os << '[' << bparams.float_placement << "]\n";
3918 case LyXParagraph::WIDE_FIG:
3919 os << "\\begin{figure*}";
3920 if (!bparams.float_placement.empty()) {
3921 os << '[' << bparams.float_placement << "]\n";
3926 case LyXParagraph::WIDE_TAB:
3927 os << "\\begin{table*}";
3928 if (!bparams.float_placement.empty()) {
3929 os << '[' << bparams.float_placement << "]\n";
3934 case LyXParagraph::ALGORITHM:
3935 os << "\\begin{algorithm}\n";
3940 if (footnotekind != LyXParagraph::FOOTNOTE
3941 || !footer_in_body) {
3942 // Process text for all floats except footnotes in body
3944 LyXLayout const & style =
3946 .Style(bparams.textclass, par->layout);
3948 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3950 if (style.isEnvironment()
3951 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3952 // Allows the use of minipages within float
3953 // environments. Shouldn't be circular because
3954 // we don't support footnotes inside
3955 // floats (yet). ARRae
3956 par = par->TeXEnvironment(buf, bparams, os,
3961 par = par->TeXOnePar(buf, bparams,
3962 os, texrow, moving_arg,
3967 if (par && !par->IsDummy() && par->depth > depth) {
3968 par = par->TeXDeeper(buf, bparams, os, texrow,
3972 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3974 // process footnotes > depth 0 or in environments separately
3975 // NOTE: Currently don't support footnotes within footnotes
3976 // even though that is possible using the \footnotemark
3978 std::ostringstream dummy;
3982 TexRow dummy_texrow;
3983 int dummy_count = 0;
3985 LyXLayout const & style =
3987 .Style(bparams.textclass, par->layout);
3989 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3991 if (style.isEnvironment()
3992 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3993 // Allows the use of minipages within float
3994 // environments. Shouldn't be circular because
3995 // we don't support footnotes inside
3996 // floats (yet). ARRae
3997 par = par->TeXEnvironment(buf, bparams,
3999 dummy, dummy_texrow,
4002 par = par->TeXOnePar(buf, bparams,
4005 dummy, dummy_texrow,
4009 if (par && !par->IsDummy() && par->depth > depth) {
4010 par = par->TeXDeeper(buf, bparams,
4012 dummy, dummy_texrow,
4016 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4018 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4019 "Footnote in a Footnote -- not supported"
4022 #ifndef HAVE_OSTREAM
4023 delete [] dummy.str();
4027 switch (footnotekind) {
4028 case LyXParagraph::FOOTNOTE:
4029 if (footer_in_body) {
4030 // This helps tell which of the multiple
4031 // footnotetexts an error was in.
4033 foot_texrow.newline();
4038 case LyXParagraph::MARGIN:
4041 case LyXParagraph::FIG:
4042 if (pextra_type == PEXTRA_FLOATFLT
4043 && (!pextra_width.empty()
4044 || !pextra_widthp.empty()))
4045 os << "\\end{floatingfigure}";
4047 os << "\\end{figure}";
4049 case LyXParagraph::TAB:
4050 os << "\\end{table}";
4052 case LyXParagraph::WIDE_FIG:
4053 os << "\\end{figure*}";
4055 case LyXParagraph::WIDE_TAB:
4056 os << "\\end{table*}";
4058 case LyXParagraph::ALGORITHM:
4059 os << "\\end{algorithm}";
4066 if (footnotekind != LyXParagraph::FOOTNOTE
4067 && footnotekind != LyXParagraph::MARGIN) {
4068 // we need to ensure that real floats like tables and figures
4069 // have their \end{} on a line of their own otherwise we can
4070 // get incorrect results when using the endfloat.sty package.
4075 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4080 bool LyXParagraph::IsDummy() const
4082 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4083 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4087 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4088 int type, char const * width,
4089 char const * widthp)
4092 pextra_width = width;
4093 pextra_widthp = widthp;
4095 if (textclasslist.Style(bparams.textclass,
4096 layout).isEnvironment()) {
4101 while (par && (par->layout == layout)
4102 && (par->depth == depth)) {
4104 par = par->Previous();
4106 par = par->FirstPhysicalPar();
4107 while (par && par->depth > depth) {
4108 par = par->Previous();
4110 par = par->FirstPhysicalPar();
4114 while (par && (par->layout == layout)
4115 && (par->depth == depth)) {
4116 par->pextra_type = type;
4117 par->pextra_width = width;
4118 par->pextra_widthp = widthp;
4119 par = par->NextAfterFootnote();
4120 if (par && (par->depth > depth))
4121 par->SetPExtraType(bparams,
4122 type, width, widthp);
4123 while (par && ((par->depth > depth) || par->IsDummy()))
4124 par = par->NextAfterFootnote();
4130 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4132 if (pextra_type == PEXTRA_NONE)
4135 pextra_type = PEXTRA_NONE;
4136 pextra_width.erase();
4137 pextra_widthp.erase();
4139 if (textclasslist.Style(bparams.textclass,
4140 layout).isEnvironment()) {
4145 while (par && (par->layout == layout)
4146 && (par->depth == depth)) {
4148 par = par->Previous();
4150 par = par->FirstPhysicalPar();
4151 while (par && par->depth > depth) {
4152 par = par->Previous();
4154 par = par->FirstPhysicalPar();
4158 while (par && (par->layout == layout)
4159 && (par->depth == depth)) {
4160 par->pextra_type = PEXTRA_NONE;
4161 par->pextra_width.erase();
4162 par->pextra_widthp.erase();
4163 par = par->NextAfterFootnote();
4164 if (par && (par->depth > depth))
4165 par->UnsetPExtraType(bparams);
4166 while (par && ((par->depth > depth) || par->IsDummy()))
4167 par = par->NextAfterFootnote();
4173 bool LyXParagraph::IsHfill(size_type pos) const
4175 return IsHfillChar(GetChar(pos));
4179 bool LyXParagraph::IsInset(size_type pos) const
4181 return IsInsetChar(GetChar(pos));
4185 bool LyXParagraph::IsFloat(size_type pos) const
4187 return IsFloatChar(GetChar(pos));
4191 bool LyXParagraph::IsNewline(size_type pos) const
4193 return pos >= 0 && IsNewlineChar(GetChar(pos));
4197 bool LyXParagraph::IsSeparator(size_type pos) const
4199 return IsSeparatorChar(GetChar(pos));
4203 bool LyXParagraph::IsLineSeparator(size_type pos) const
4205 return IsLineSeparatorChar(GetChar(pos));
4209 bool LyXParagraph::IsKomma(size_type pos) const
4211 return IsKommaChar(GetChar(pos));
4215 /// Used by the spellchecker
4216 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4218 unsigned char c = GetChar(pos);
4219 if (IsLetterChar(c))
4221 // '\0' is not a letter, allthough every string contains "" (below)
4224 // We want to pass the ' and escape chars to ispell
4225 string extra = lyxrc.isp_esc_chars + '\'';
4229 return contains(extra, ch);
4233 bool LyXParagraph::IsWord(size_type pos ) const
4235 return IsWordChar(GetChar(pos)) ;
4240 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4243 return FirstPhysicalPar()->getParLanguage(bparams);
4244 else if (size() > 0)
4248 return GetFirstFontSettings().language();
4251 for (size_type pos = 0; pos < size(); ++pos)
4253 return GetFontSettings(bparams, pos).language();
4254 return GetFirstFontSettings().language();
4258 return previous->getParLanguage(bparams);
4260 return bparams.language_info;
4264 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4266 return lyxrc.rtl_support && !table
4267 && getParLanguage(bparams)->RightToLeft();
4271 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4272 Language const * from, Language const * to)
4274 for(size_type i = 0; i < size(); ++i) {
4275 LyXFont font = GetFontSettings(bparams, i);
4276 if (font.language() == from) {
4277 font.setLanguage(to);
4284 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4286 Language const * doc_language =
4287 bparams.language_info;
4288 for(size_type i = 0; i < size(); ++i) {
4289 LyXFont font = GetFontSettings(bparams, i);
4290 if (font.language() != doc_language)
4297 // Convert the paragraph to a string.
4298 // Used for building the table of contents
4299 string LyXParagraph::String(Buffer const * buffer, bool label)
4301 BufferParams const & bparams = buffer->params;
4303 if (label && !IsDummy() && !labelstring.empty())
4304 s += labelstring + ' ';
4305 string::size_type len = s.size();
4307 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4308 unsigned char c = GetChar(i);
4311 else if (c == META_INSET &&
4312 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4314 std::ostringstream ost;
4315 GetInset(i)->Ascii(buffer, ost);
4318 GetInset(i)->Ascii(buffer, ost);
4321 s += subst(ost.str(),'\n',' ');
4326 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4327 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4328 s += NextAfterFootnote()->String(buffer, false);
4333 if (isRightToLeftPar(bparams))
4334 reverse(s.begin() + len,s.end());
4340 string LyXParagraph::String(Buffer const * buffer,
4341 LyXParagraph::size_type beg,
4342 LyXParagraph::size_type end)
4349 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4351 if (cell >= table->NumberOfCellsInRow(actcell))
4359 if (beg == 0 && !IsDummy() && !labelstring.empty())
4360 s += labelstring + ' ';
4362 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4363 unsigned char c = GetChar(i);
4366 else if (c == META_INSET) {
4368 std::ostringstream ost;
4369 GetInset(i)->Ascii(buffer, ost);
4372 GetInset(i)->Ascii(buffer, ost);
4376 } else if (table && IsNewlineChar(c)) {
4377 if (cell >= table->NumberOfCellsInRow(actcell)) {
4388 //if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4389 // s += NextAfterFootnote()->String(false);
4395 void LyXParagraph::SetInsetOwner(Inset *i)
4398 for (InsetList::const_iterator cit = insetlist.begin();
4399 cit != insetlist.end(); ++cit) {
4401 (*cit).inset->setOwner(i);
4406 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4409 for (InsetList::const_iterator cit = insetlist.begin();
4410 cit != insetlist.end(); ++cit) {
4412 if ((*cit).inset->IsTextInset()) {
4413 static_cast<UpdatableInset *>
4414 ((*cit).inset)->deleteLyXText(bv);