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"
27 #include "bufferparams.h"
28 #include "support/FileInfo.h"
29 #include "support/LAssert.h"
31 #include "LaTeXFeatures.h"
32 #include "insets/insetinclude.h"
33 #include "insets/insetbib.h"
34 #include "insets/insettext.h"
35 #include "support/filetools.h"
36 #include "lyx_gui_misc.h"
38 #include "support/lyxmanip.h"
39 #include "BufferView.h"
46 using std::lower_bound;
47 using std::upper_bound;
50 int tex_code_break_column = 72; // needs non-zero initialization. set later.
51 // this is a bad idea, but how can LyXParagraph find its buffer to get
52 // parameters? (JMarc)
53 extern BufferView * current_view;
54 extern string bibitemWidest(BufferView *);
56 // this is a minibuffer
57 static char minibuffer_char;
58 static LyXFont minibuffer_font;
59 static Inset * minibuffer_inset;
62 // Initialization of the counter for the paragraph id's,
63 // declared in lyxparagraph.h
64 unsigned int LyXParagraph::paragraph_id = 0;
67 LyXParagraph::LyXParagraph()
69 text.reserve(500); // is this number too big?
71 for (int i = 0; i < 10; ++i) setCounter(i , 0);
78 footnoteflag = LyXParagraph::NO_FOOTNOTE;
79 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
81 align = LYX_ALIGN_BLOCK;
84 /* table stuff -- begin*/
86 /* table stuff -- end*/
90 bibkey = 0; // ale970302
95 // This konstruktor inserts the new paragraph in a list.
96 LyXParagraph::LyXParagraph(LyXParagraph * par)
99 par->text.resize(par->text.size());
101 for (int i = 0; i < 10; ++i) setCounter(i, 0);
105 // double linked list begin
108 next->previous = this;
110 previous->next = this;
113 footnoteflag = LyXParagraph::NO_FOOTNOTE;
114 footnotekind = LyXParagraph::FOOTNOTE;
117 /* table stuff -- begin*/
119 /* table stuff -- end*/
122 id_ = paragraph_id++;
124 bibkey = 0; // ale970302
130 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
131 BufferParams const & params,
132 char footflag, char dth) const
136 footnoteflag != LyXParagraph::NO_FOOTNOTE ||
138 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
143 // The beginning or the end of a footnote environment?
144 if (footflag != footnoteflag) {
145 footflag = footnoteflag;
147 os << "\n\\begin_float "
148 << string_footnotekinds[footnotekind]
151 os << "\n\\end_float ";
155 // The beginning or end of a deeper (i.e. nested) area?
158 while (depth > dth) {
159 os << "\n\\begin_deeper ";
163 while (depth < dth) {
164 os << "\n\\end_deeper ";
170 // First write the layout
172 << textclasslist.NameOfLayout(params.textclass, layout)
175 // Maybe some vertical spaces.
176 if (added_space_top.kind() != VSpace::NONE)
177 os << "\\added_space_top "
178 << added_space_top.asLyXCommand() << " ";
179 if (added_space_bottom.kind() != VSpace::NONE)
180 os << "\\added_space_bottom "
181 << added_space_bottom.asLyXCommand() << " ";
183 // Maybe the paragraph has special spacing
184 spacing.writeFile(os, true);
186 // The labelwidth string used in lists.
187 if (!labelwidthstring.empty())
188 os << "\\labelwidthstring "
189 << labelwidthstring << '\n';
191 // Lines above or below?
195 os << "\\line_bottom ";
197 // Pagebreaks above or below?
199 os << "\\pagebreak_top ";
200 if (pagebreak_bottom)
201 os << "\\pagebreak_bottom ";
203 // Start of appendix?
204 if (start_of_appendix)
205 os << "\\start_of_appendix ";
212 if (align != LYX_ALIGN_LAYOUT) {
215 case LYX_ALIGN_LEFT: h = 1; break;
216 case LYX_ALIGN_RIGHT: h = 2; break;
217 case LYX_ALIGN_CENTER: h = 3; break;
218 default: h = 0; break;
220 os << "\\align " << string_align[h] << " ";
222 if (pextra_type != PEXTRA_NONE) {
223 os << "\\pextra_type " << pextra_type;
224 if (pextra_type == PEXTRA_MINIPAGE) {
225 os << " \\pextra_alignment "
228 os << " \\pextra_hfill "
230 if (pextra_start_minipage)
231 os << " \\pextra_start_minipage "
232 << pextra_start_minipage;
234 if (!pextra_width.empty()) {
235 os << " \\pextra_width "
236 << VSpace(pextra_width).asLyXCommand();
237 } else if (!pextra_widthp.empty()) {
238 os << " \\pextra_widthp "
245 // Dummy layout. This means that a footnote ended.
246 os << "\n\\end_float ";
247 footflag = LyXParagraph::NO_FOOTNOTE;
251 // It might be a table.
253 os << "\\LyXTable\n";
259 bibkey->Write(buf, os);
261 LyXFont font1(LyXFont::ALL_INHERIT, params.language_info);
264 for (size_type i = 0; i < size(); ++i) {
270 // Write font changes
271 LyXFont font2 = GetFontSettings(params, i);
272 if (font2 != font1) {
273 font2.lyxWriteChanges(font1, os);
278 value_type c = GetChar(i);
282 Inset const * inset = GetInset(i);
284 if (inset->DirectWrite()) {
285 // international char, let it write
286 // code directly so it's shorter in
288 inset->Write(buf, os);
290 os << "\n\\begin_inset ";
291 inset->Write(buf, os);
292 os << "\n\\end_inset \n\n";
298 os << "\n\\newline \n";
302 os << "\n\\hfill \n";
306 os << "\n\\backslash \n";
310 if (i + 1 < size() && GetChar(i + 1) == ' ') {
317 if ((column > 70 && c == ' ')
322 // this check is to amend a bug. LyX sometimes
323 // inserts '\0' this could cause problems.
327 lyxerr << "ERROR (LyXParagraph::writeFile):"
328 " NULL char in structure." << endl;
334 // now write the next paragraph
336 next->writeFile(buf, os, params, footflag, dth);
340 void LyXParagraph::validate(LaTeXFeatures & features) const
342 BufferParams const & params = features.bufferParams();
345 // this will be useful later
346 LyXLayout const & layout =
347 textclasslist.Style(params.textclass,
352 if (line_top || line_bottom)
353 features.lyxline = true;
354 if (!spacing.isDefault())
355 features.setspace = true;
358 features.layout[GetLayout()] = true;
361 Language const * doc_language = params.language_info;
363 for (FontList::const_iterator cit = fontlist.begin();
364 cit != fontlist.end(); ++cit) {
365 if ((*cit).font.noun() == LyXFont::ON) {
366 lyxerr[Debug::LATEX] << "font.noun: "
367 << (*cit).font.noun()
369 features.noun = true;
370 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
371 << (*cit).font.stateText(0)
374 switch ((*cit).font.color()) {
376 case LColor::inherit:
380 features.color = true;
381 lyxerr[Debug::LATEX] << "Color enabled. Font: "
382 << (*cit).font.stateText(0)
386 Language const * language = (*cit).font.language();
387 if (language != doc_language) {
388 features.UsedLanguages.insert(language);
389 lyxerr[Debug::LATEX] << "Found language "
390 << language->lang() << endl;
395 for (InsetList::const_iterator cit = insetlist.begin();
396 cit != insetlist.end(); ++cit) {
398 (*cit).inset->Validate(features);
402 if (table && table->IsLongTable())
403 features.longtable = true;
405 if (pextra_type == PEXTRA_INDENT)
406 features.LyXParagraphIndent = true;
407 if (pextra_type == PEXTRA_FLOATFLT)
408 features.floatflt = true;
410 if (layout.needprotect
411 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
412 features.NeedLyXFootnoteCode = true;
414 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
415 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
416 features.NeedLyXMinipageIndent = true;
418 if (table && table->NeedRotating())
419 features.rotating = true;
422 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
423 features.algorithm = true;
428 // First few functions needed for cut and paste and paragraph breaking.
429 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
430 LyXParagraph::size_type pos) const
432 minibuffer_char = GetChar(pos);
433 minibuffer_font = GetFontSettings(bparams, pos);
434 minibuffer_inset = 0;
435 if (minibuffer_char == LyXParagraph::META_INSET) {
437 minibuffer_inset = GetInset(pos)->Clone();
439 minibuffer_inset = 0;
440 minibuffer_char = ' ';
441 // This reflects what GetInset() does (ARRae)
447 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
448 LyXParagraph::size_type pos)
450 minibuffer_char = GetChar(pos);
451 minibuffer_font = GetFontSettings(bparams, pos);
452 minibuffer_inset = 0;
453 if (minibuffer_char == LyXParagraph::META_INSET) {
455 minibuffer_inset = GetInset(pos);
456 // This is a little hack since I want exactly
457 // the inset, not just a clone. Otherwise
458 // the inset would be deleted when calling Erase(pos)
460 InsetTable search_elem(pos, 0);
461 InsetList::iterator it =
462 lower_bound(insetlist.begin(),
464 search_elem, matchIT());
465 if (it != insetlist.end() && (*it).pos == pos)
468 minibuffer_inset = 0;
469 minibuffer_char = ' ';
470 // This reflects what GetInset() does (ARRae)
475 // Erase(pos); now the caller is responsible for that.
479 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
481 if ((minibuffer_char == LyXParagraph::META_INSET) &&
482 !InsertInsetAllowed(minibuffer_inset))
484 if (minibuffer_char == LyXParagraph::META_INSET)
485 InsertInset(pos, minibuffer_inset, minibuffer_font);
487 InsertChar(pos, minibuffer_char, minibuffer_font);
495 void LyXParagraph::Clear()
500 pagebreak_top = false;
501 pagebreak_bottom = false;
503 added_space_top = VSpace(VSpace::NONE);
504 added_space_bottom = VSpace(VSpace::NONE);
505 spacing.set(Spacing::Default);
507 align = LYX_ALIGN_LAYOUT;
511 pextra_type = PEXTRA_NONE;
512 pextra_width.erase();
513 pextra_widthp.erase();
514 pextra_alignment = MINIPAGE_ALIGN_TOP;
515 pextra_hfill = false;
516 pextra_start_minipage = false;
519 labelwidthstring.erase();
523 start_of_appendix = false;
527 // the destructor removes the new paragraph from the list
528 LyXParagraph::~LyXParagraph()
531 previous->next = next;
533 next->previous = previous;
535 for (InsetList::iterator it = insetlist.begin();
536 it != insetlist.end(); ++it) {
540 /* table stuff -- begin*/
542 /* table stuff -- end*/
548 //lyxerr << "LyXParagraph::paragraph_id = "
549 // << LyXParagraph::paragraph_id << endl;
553 void LyXParagraph::Erase(LyXParagraph::size_type pos)
556 // > because last is the next unused position, and you can
557 // use it if you want
559 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
560 NextAfterFootnote()->Erase(pos - text.size() - 1);
562 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
563 "position does not exist." << endl;
567 Assert(pos < size());
570 if (pos < size()) { // last is free for insertation, but should be empty
572 // if it is an inset, delete the inset entry
573 if (text[pos] == LyXParagraph::META_INSET) {
575 InsetTable search_inset(pos, 0);
576 InsetList::iterator it =
577 lower_bound(insetlist.begin(),
579 search_inset, matchIT());
580 if (it != insetlist.end() && (*it).pos == pos) {
585 text.erase(text.begin() + pos);
587 // Erase entries in the tables.
588 FontTable search_font(pos, LyXFont());
590 FontList::iterator it =
591 lower_bound(fontlist.begin(),
593 search_font, matchFT());
594 if (it != fontlist.end() && (*it).pos == pos &&
596 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
597 // If it is a multi-character font
598 // entry, we just make it smaller
599 // (see update below), otherwise we
601 unsigned int i = it - fontlist.begin();
602 fontlist.erase(fontlist.begin() + i);
603 it = fontlist.begin() + i;
604 if (i > 0 && i < fontlist.size() &&
605 fontlist[i-1].font == fontlist[i].font) {
606 fontlist.erase(fontlist.begin() + i-1);
607 it = fontlist.begin() + i-1;
611 // Update all other entries.
612 FontList::iterator fend = fontlist.end();
613 for (; it != fend; ++it)
616 // Update the inset table.
617 InsetTable search_inset(pos, 0);
618 InsetList::iterator lend = insetlist.end();
619 for (InsetList::iterator it =
620 upper_bound(insetlist.begin(),
622 search_inset, matchIT());
627 lyxerr << "ERROR (LyXParagraph::Erase): "
628 "can't erase non-existant char." << endl;
634 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
635 LyXParagraph::value_type c)
637 LyXFont f(LyXFont::ALL_INHERIT);
638 InsertChar(pos, c, f);
642 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
643 LyXParagraph::value_type c,
644 LyXFont const & font)
647 // > because last is the next unused position, and you can
648 // use it if you want
651 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
652 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
655 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
656 "position does not exist." << endl;
660 Assert(pos <= size());
662 text.insert(text.begin() + pos, c);
663 // Update the font table.
664 FontTable search_font(pos, LyXFont());
665 for (FontList::iterator it = lower_bound(fontlist.begin(),
667 search_font, matchFT());
668 it != fontlist.end(); ++it)
671 // Update the inset table.
672 InsetTable search_inset(pos, 0);
673 for (InsetList::iterator it = lower_bound(insetlist.begin(),
675 search_inset, matchIT());
676 it != insetlist.end(); ++it)
683 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
686 LyXFont f(LyXFont::ALL_INHERIT);
687 InsertInset(pos, inset, f);
691 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
692 Inset * inset, LyXFont const & font)
697 // > because last is the next unused position, and you can
698 // use it if you want
701 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
703 ->InsertInset(pos - text.size() - 1,
706 lyxerr << "ERROR (LyXParagraph::InsertInset): "
707 "position does not exist: " << pos << endl;
711 Assert(pos <= size());
714 InsertChar(pos, META_INSET, font);
715 Assert(text[pos] == META_INSET);
717 // Add a new entry in the inset table.
718 InsetTable search_inset(pos, 0);
719 InsetList::iterator it = lower_bound(insetlist.begin(),
721 search_inset, matchIT());
722 if (it != insetlist.end() && (*it).pos == pos)
723 lyxerr << "ERROR (LyXParagraph::InsertInset): "
724 "there is an inset in position: " << pos << endl;
726 insetlist.insert(it, InsetTable(pos, inset));
728 inset->setOwner(inset_owner);
732 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
734 //lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
737 return inset_owner->InsertInsetAllowed(inset);
742 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
747 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
748 return NextAfterFootnote()
749 ->GetInset(pos - text.size() - 1);
751 lyxerr << "ERROR (LyXParagraph::GetInset): "
752 "position does not exist: "
758 Assert(pos < size());
761 InsetTable search_inset(pos, 0);
762 InsetList::iterator it = lower_bound(insetlist.begin(),
764 search_inset, matchIT());
765 if (it != insetlist.end() && (*it).pos == pos)
768 lyxerr << "ERROR (LyXParagraph::GetInset): "
769 "Inset does not exist: " << pos << endl;
772 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
773 // Did this commenting out introduce a bug? So far I have not
774 // see any, please enlighten me. (Lgb)
775 // My guess is that since the inset does not exist, we might
776 // as well replace it with a space to prevent craches. (Asger)
781 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
786 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
787 return NextAfterFootnote()
788 ->GetInset(pos - text.size() - 1);
790 lyxerr << "ERROR (LyXParagraph::GetInset): "
791 "position does not exist: "
797 Assert(pos < size());
800 InsetTable search_inset(pos, 0);
801 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
803 search_inset, matchIT());
804 if (cit != insetlist.end() && (*cit).pos == pos)
807 lyxerr << "ERROR (LyXParagraph::GetInset): "
808 "Inset does not exist: " << pos << endl;
810 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
811 // Did this commenting out introduce a bug? So far I have not
812 // see any, please enlighten me. (Lgb)
813 // My guess is that since the inset does not exist, we might
814 // as well replace it with a space to prevent craches. (Asger)
819 // Gets uninstantiated font setting at position.
820 // Optimized after profiling. (Asger)
821 LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
822 LyXParagraph::size_type pos) const
825 Assert(pos <= size());
830 FontTable search_font(pos, LyXFont());
831 FontList::const_iterator cit = lower_bound(fontlist.begin(),
833 search_font, matchFT());
834 if (cit != fontlist.end())
840 // > because last is the next unused position, and you can
841 // use it if you want
842 else if (pos > size()) {
844 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
845 return NextAfterFootnote()
846 ->GetFontSettings(bparams,
847 pos - text.size() - 1);
849 // Why is it an error to ask for the font of a
850 // position that does not exist? Would it be
851 // enough for this to be enabled on debug?
852 // We want strict error checking, but it's ok to only
853 // have it when debugging. (Asger)
854 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
855 "position does not exist. "
856 << pos << " (" << static_cast<int>(pos)
860 return GetFontSettings(bparams, pos - 1);
863 if (pos == size() && size())
864 return GetFontSettings(bparams, pos - 1);
868 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
870 //return LyXFont(LyXFont::ALL_INHERIT);
873 // Gets uninstantiated font setting at position 0
874 LyXFont const LyXParagraph::GetFirstFontSettings() const
877 if (!fontlist.empty())
878 return fontlist[0].font;
882 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
883 return NextAfterFootnote()->GetFirstFontSettings();
885 return LyXFont(LyXFont::ALL_INHERIT);
889 // Gets the fully instantiated font at a given position in a paragraph
890 // This is basically the same function as LyXText::GetFont() in text2.C.
891 // The difference is that this one is used for generating the LaTeX file,
892 // and thus cosmetic "improvements" are disallowed: This has to deliver
893 // the true picture of the buffer. (Asger)
894 // If position is -1, we get the layout font of the paragraph.
895 // If position is -2, we get the font of the manual label of the paragraph.
896 LyXFont const LyXParagraph::getFont(BufferParams const & bparams,
897 LyXParagraph::size_type pos) const
900 LyXLayout const & layout =
901 textclasslist.Style(bparams.textclass,
903 LyXParagraph::size_type main_body = 0;
904 if (layout.labeltype == LABEL_MANUAL)
905 main_body = BeginningOfMainBody();
910 layoutfont = layout.labelfont;
912 layoutfont = layout.font;
913 tmpfont = GetFontSettings(bparams, pos);
914 tmpfont.realize(layoutfont);
916 // process layoutfont for pos == -1 and labelfont for pos < -1
918 tmpfont = layout.font;
920 tmpfont = layout.labelfont;
921 tmpfont.setLanguage(getParLanguage(bparams));
924 // check for environment font information
925 char par_depth = GetDepth();
926 LyXParagraph const * par = this;
927 while (par && par_depth && !tmpfont.resolved()) {
928 par = par->DepthHook(par_depth - 1);
930 tmpfont.realize(textclasslist.
931 Style(bparams.textclass,
932 par->GetLayout()).font);
933 par_depth = par->GetDepth();
937 tmpfont.realize(textclasslist
938 .TextClass(bparams.textclass)
944 /// Returns the height of the highest font in range
946 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
947 LyXParagraph::size_type endpos) const
949 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
950 if (fontlist.empty())
953 FontTable end_search(endpos, LyXFont());
954 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
956 end_search, matchFT());
957 if (end_it != fontlist.end())
960 FontTable start_search(startpos, LyXFont());
961 for (FontList::const_iterator cit =
962 lower_bound(fontlist.begin(),
964 start_search, matchFT());
965 cit != end_it; ++cit) {
966 LyXFont::FONT_SIZE size = (*cit).font.size();
967 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
974 LyXParagraph::value_type
975 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
980 Assert(pos <= size());
981 if (!size() || pos == size()) return '\0';
992 // > because last is the next unused position, and you can
993 // use it if you want
994 else if (pos > size()) {
995 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
996 return NextAfterFootnote()
997 ->GetChar(pos - text.size() - 1);
1000 lyxerr << "ERROR (LyXParagraph::GetChar const): "
1001 "position does not exist."
1002 << pos << " (" << static_cast<int>(pos)
1008 // We should have a footnote environment.
1009 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1010 // Notice that LyX does request the
1011 // last char from time to time. (Asger)
1012 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1013 // "expected footnote." << endl;
1016 switch (next->footnotekind) {
1017 case LyXParagraph::FOOTNOTE:
1018 return LyXParagraph::META_FOOTNOTE;
1019 case LyXParagraph::MARGIN:
1020 return LyXParagraph::META_MARGIN;
1021 case LyXParagraph::FIG:
1022 case LyXParagraph::WIDE_FIG:
1023 return LyXParagraph::META_FIG;
1024 case LyXParagraph::TAB:
1025 case LyXParagraph::WIDE_TAB:
1026 return LyXParagraph::META_TAB;
1027 case LyXParagraph::ALGORITHM:
1028 return LyXParagraph::META_ALGORITHM;
1030 return '\0'; // to shut up gcc
1036 // return an string of the current word, and the end of the word in lastpos.
1037 string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1039 Assert(lastpos >= 0);
1041 // the current word is defined as starting at the first character
1042 // from the immediate left of lastpospos which meets the definition
1043 // of IsLetter(), continuing to the last character to the right
1044 // of this meeting IsLetter.
1050 // move back until we have a letter
1052 //there's no real reason to have firstpos & lastpos as
1053 //separate variables as this is written, but maybe someon
1054 // will want to return firstpos in the future.
1056 //since someone might have typed a punctuation first
1057 int firstpos = lastpos;
1059 while ((firstpos >= 0) && !IsLetter(firstpos))
1062 // now find the beginning by looking for a nonletter
1064 while ((firstpos>= 0) && IsLetter(firstpos))
1067 // the above is now pointing to the preceeding non-letter
1071 // so copy characters into theword until we get a nonletter
1072 // note that this can easily exceed lastpos, wich means
1073 // that if used in the middle of a word, the whole word
1076 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1084 #warning Remember to get rid of this one. (Lgb)
1086 LyXParagraph::size_type LyXParagraph::Last() const
1089 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1090 return text.size() + NextAfterFootnote()->Last() + 1;
1091 // the 1 is the symbol
1100 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1102 // > because last is the next unused position, and you can
1103 // use it if you want
1106 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1107 return NextAfterFootnote()
1108 ->ParFromPos(pos - text.size() - 1);
1110 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1111 "position does not exist." << endl;
1120 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1122 // > because last is the next unused position, and you can
1123 // use it if you want
1126 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1127 return NextAfterFootnote()
1128 ->PositionInParFromPos(pos - text.size() - 1);
1131 "ERROR (LyXParagraph::PositionInParFromPos): "
1132 "position does not exist." << endl;
1141 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1142 LyXFont const & font)
1145 // > because last is the next unused position, and you can
1146 // use it if you want
1149 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1150 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1153 lyxerr << "ERROR (LyXParagraph::SetFont): "
1154 "position does not exist." << endl;
1159 Assert(pos <= size());
1162 // First, reduce font against layout/label font
1163 // Update: The SetCharFont() routine in text2.C already
1164 // reduces font, so we don't need to do that here. (Asger)
1165 // No need to simplify this because it will disappear
1166 // in a new kernel. (Asger)
1167 // Next search font table
1169 FontTable search_font(pos, LyXFont());
1170 FontList::iterator it = lower_bound(fontlist.begin(),
1172 search_font, matchFT());
1173 unsigned int i = it - fontlist.begin();
1174 bool notfound = it == fontlist.end();
1176 if (!notfound && fontlist[i].font == font)
1179 bool begin = pos == 0 || notfound ||
1180 (i > 0 && fontlist[i-1].pos == pos - 1);
1181 // Is position pos is a beginning of a font block?
1182 bool end = !notfound && fontlist[i].pos == pos;
1183 // Is position pos is the end of a font block?
1184 if (begin && end) { // A single char block
1185 if (i+1 < fontlist.size() &&
1186 fontlist[i+1].font == font) {
1187 // Merge the singleton block with the next block
1188 fontlist.erase(fontlist.begin() + i);
1189 if (i > 0 && fontlist[i-1].font == font)
1190 fontlist.erase(fontlist.begin() + i-1);
1191 } else if (i > 0 && fontlist[i-1].font == font) {
1192 // Merge the singleton block with the previous block
1193 fontlist[i-1].pos = pos;
1194 fontlist.erase(fontlist.begin() + i);
1196 fontlist[i].font = font;
1198 if (i > 0 && fontlist[i-1].font == font)
1199 fontlist[i-1].pos = pos;
1201 fontlist.insert(fontlist.begin() + i,
1202 FontTable(pos, font));
1204 fontlist[i].pos = pos - 1;
1205 if (!(i+1 < fontlist.size() &&
1206 fontlist[i+1].font == font))
1207 fontlist.insert(fontlist.begin() + i+1,
1208 FontTable(pos, font));
1209 } else { // The general case. The block is splitted into 3 blocks
1210 fontlist.insert(fontlist.begin() + i,
1211 FontTable(pos - 1, fontlist[i].font));
1212 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1217 // This function is able to hide closed footnotes.
1218 LyXParagraph * LyXParagraph::Next()
1221 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1222 LyXParagraph * tmp = next;
1224 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1226 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1227 return tmp->Next(); /* there can be more than one
1228 footnote in a logical
1231 return next; // This should never happen!
1239 LyXParagraph * LyXParagraph::NextAfterFootnote()
1241 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1242 LyXParagraph * tmp = next;
1243 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1245 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1246 return tmp; /* there can be more than one footnote
1247 in a logical paragraph */
1249 return next; // This should never happen!
1257 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1259 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1260 LyXParagraph * tmp = next;
1261 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
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 next; // This should never happen!
1275 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1278 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1280 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1281 tmp = tmp->previous;
1282 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1283 return tmp; /* there can be more than one footnote
1284 in a logical paragraph */
1286 return previous; // This should never happen!
1294 LyXParagraph * LyXParagraph::LastPhysicalPar()
1296 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1299 LyXParagraph * tmp = this;
1301 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1302 tmp = tmp->NextAfterFootnote();
1310 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1312 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1315 LyXParagraph const * tmp = this;
1317 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1318 tmp = tmp->NextAfterFootnote();
1326 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1330 LyXParagraph * tmppar = this;
1334 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1335 tmppar = tmppar->previous;
1346 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1350 LyXParagraph const * tmppar = this;
1354 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1355 tmppar = tmppar->previous;
1365 // This function is able to hide closed footnotes.
1366 LyXParagraph * LyXParagraph::Previous()
1369 LyXParagraph * tmp = previous;
1374 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1375 tmp = tmp->previous;
1377 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1378 tmp = tmp->previous;
1379 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1380 return tmp->next->Previous();
1390 // This function is able to hide closed footnotes.
1391 LyXParagraph const * LyXParagraph::Previous() const
1394 LyXParagraph * tmp = previous;
1398 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1399 tmp = tmp->previous;
1401 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1402 tmp = tmp->previous;
1403 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1404 return tmp->next->Previous();
1414 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1415 LyXParagraph::size_type pos,
1420 // create a new paragraph
1423 size_type pos_first;
1424 LyXParagraph * par = ParFromPos(pos);
1425 LyXParagraph * firstpar = FirstPhysicalPar();
1427 LyXParagraph * tmp = new LyXParagraph(par);
1429 //LyXParagraph * par = this;
1430 //LyXParagraph * firstpar = this;
1431 LyXParagraph * tmp = new LyXParagraph(this);
1435 tmp->footnoteflag = footnoteflag;
1436 tmp->footnotekind = footnotekind;
1438 // this is an idea for a more userfriendly layout handling, I will
1439 // see what the users say
1442 // layout stays the same with latex-environments
1444 tmp->SetOnlyLayout(bparams, firstpar->layout);
1445 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1448 // layout stays the same with latex-environments
1450 tmp->SetOnlyLayout(bparams, layout);
1451 tmp->SetLabelWidthString(labelwidthstring);
1455 if (Last() > pos || !Last() || flag == 2) {
1456 tmp->SetOnlyLayout(bparams, firstpar->layout);
1457 tmp->align = firstpar->align;
1458 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1460 tmp->line_bottom = firstpar->line_bottom;
1461 firstpar->line_bottom = false;
1462 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1463 firstpar->pagebreak_bottom = false;
1464 tmp->added_space_bottom = firstpar->added_space_bottom;
1465 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1467 tmp->depth = firstpar->depth;
1468 tmp->noindent = firstpar->noindent;
1470 if (Last() > pos || !Last() || flag == 2) {
1471 tmp->SetOnlyLayout(bparams, layout);
1473 tmp->SetLabelWidthString(labelwidthstring);
1475 tmp->line_bottom = line_bottom;
1476 line_bottom = false;
1477 tmp->pagebreak_bottom = pagebreak_bottom;
1478 pagebreak_bottom = false;
1479 tmp->added_space_bottom = added_space_bottom;
1480 added_space_bottom = VSpace(VSpace::NONE);
1483 tmp->noindent = noindent;
1485 // copy everything behind the break-position
1486 // to the new paragraph
1489 while (ParFromPos(pos_first) != par)
1491 pos_end = pos_first + par->text.size() - 1;
1494 for (i = j = pos; i <= pos_end; ++i) {
1495 par->CutIntoMinibuffer(bparams, i - pos_first);
1496 if (tmp->InsertFromMinibuffer(j - pos))
1499 tmp->text.resize(tmp->text.size());
1500 for (i = pos_end; i >= pos; --i)
1501 par->Erase(i - pos_first);
1503 par->text.resize(par->text.size());
1505 size_type pos_end = text.size() - 1;
1507 for (i = j = pos; i <= pos_end; ++i) {
1508 CutIntoMinibuffer(bparams, i);
1509 if (tmp->InsertFromMinibuffer(j - pos))
1513 for (i = pos_end; i >= pos; --i)
1521 // just an idea of me
1523 tmp->line_top = firstpar->line_top;
1524 tmp->pagebreak_top = firstpar->pagebreak_top;
1525 tmp->added_space_top = firstpar->added_space_top;
1526 tmp->bibkey = firstpar->bibkey;
1528 // layout stays the same with latex-environments
1530 firstpar->SetOnlyLayout(bparams, tmp->layout);
1531 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1532 firstpar->depth = tmp->depth;
1536 // just an idea of me
1538 tmp->line_top = line_top;
1539 tmp->pagebreak_top = pagebreak_top;
1540 tmp->added_space_top = added_space_top;
1541 tmp->bibkey = bibkey;
1543 // layout stays the same with latex-environments
1545 SetOnlyLayout(bparams, tmp->layout);
1546 SetLabelWidthString(tmp->labelwidthstring);
1554 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1557 par = par->FirstPhysicalPar();
1558 footnoteflag = par->footnoteflag;
1559 footnotekind = par->footnotekind;
1561 layout = par->layout;
1562 align = par-> align;
1563 SetLabelWidthString(par->labelwidthstring);
1565 line_bottom = par->line_bottom;
1566 pagebreak_bottom = par->pagebreak_bottom;
1567 added_space_bottom = par->added_space_bottom;
1569 line_top = par->line_top;
1570 pagebreak_top = par->pagebreak_top;
1571 added_space_top = par->added_space_top;
1573 spacing = par->spacing;
1575 pextra_type = par->pextra_type;
1576 pextra_width = par->pextra_width;
1577 pextra_widthp = par->pextra_widthp;
1578 pextra_alignment = par->pextra_alignment;
1579 pextra_hfill = par->pextra_hfill;
1580 pextra_start_minipage = par->pextra_start_minipage;
1582 noindent = par->noindent;
1588 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1590 LyXParagraph * tmppar = this;
1593 && tmppar->previous->footnoteflag ==
1594 LyXParagraph::CLOSED_FOOTNOTE)
1595 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1596 tmppar = tmppar->previous;
1599 return this; // This should never happen!
1606 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1608 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1623 && (IsNewline(0) || IsLineSeparator(0))){
1632 LyXParagraph * LyXParagraph::Clone() const
1634 // create a new paragraph
1635 LyXParagraph * result = new LyXParagraph;
1637 result->MakeSameLayout(this);
1639 // this is because of the dummy layout of the paragraphs that
1641 result->layout = layout;
1644 /* table stuff -- begin*/
1646 result->table = table->Clone();
1649 /* table stuff -- end*/
1651 result->inset_owner = inset_owner;
1655 result->bibkey = static_cast<InsetBibKey *>(bibkey->Clone());
1659 // copy everything behind the break-position to the new paragraph
1661 result->text = text;
1662 result->fontlist = fontlist;
1663 result->insetlist = insetlist;
1664 for (InsetList::iterator it = result->insetlist.begin();
1665 it != result->insetlist.end(); ++it)
1666 (*it).inset = (*it).inset->Clone();
1671 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1674 par = par->FirstPhysicalPar();
1679 par->footnoteflag == footnoteflag &&
1680 par->footnotekind == footnotekind &&
1682 par->layout == layout &&
1684 par->align == align &&
1686 par->line_bottom == line_bottom &&
1687 par->pagebreak_bottom == pagebreak_bottom &&
1688 par->added_space_bottom == added_space_bottom &&
1690 par->line_top == line_top &&
1691 par->pagebreak_top == pagebreak_top &&
1692 par->added_space_top == added_space_top &&
1694 par->spacing == spacing &&
1696 par->pextra_type == pextra_type &&
1697 par->pextra_width == pextra_width &&
1698 par->pextra_widthp == pextra_widthp &&
1699 par->pextra_alignment == pextra_alignment &&
1700 par->pextra_hfill == pextra_hfill &&
1701 par->pextra_start_minipage == pextra_start_minipage &&
1703 par->table == table && // what means: NO TABLE AT ALL
1706 par->noindent == noindent &&
1707 par->depth == depth);
1711 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1712 LyXParagraph::size_type pos)
1715 // create a new paragraph
1716 LyXParagraph * par = ParFromPos(pos);
1718 LyXParagraph * tmp = new LyXParagraph(par);
1720 tmp->MakeSameLayout(par);
1722 // When can pos < Last()?
1723 // I guess pos == Last() is possible.
1725 // copy everything behind the break-position to the new
1727 size_type pos_first = 0;
1728 while (ParFromPos(pos_first) != par)
1730 size_type pos_end = pos_first + par->text.size() - 1;
1733 for (i = j = pos; i <= pos_end; ++i) {
1734 par->CutIntoMinibuffer(bparams, i - pos_first);
1735 if (tmp->InsertFromMinibuffer(j - pos))
1738 tmp->text.resize(tmp->text.size());
1739 for (size_type i = pos_end; i >= pos; --i)
1740 par->Erase(i - pos_first);
1742 par->text.resize(par->text.size());
1745 // create a new paragraph
1746 LyXParagraph * tmp = new LyXParagraph(this);
1747 tmp->MakeSameLayout(this);
1749 // When can pos > Last()?
1750 // I guess pos == Last() is possible.
1752 // copy everything behind the break-position to the new
1754 size_type pos_end = text.size() - 1;
1757 for (i = j = pos; i <= pos_end; ++i) {
1758 CutIntoMinibuffer(bparams, i);
1759 if (tmp->InsertFromMinibuffer(j - pos))
1765 for (size_type i = pos_end; i >= pos; --i)
1774 // Be carefull, this does not make any check at all.
1775 // This method has wrong name, it combined this par with the next par.
1776 // In that sense it is the reverse of break paragraph. (Lgb)
1777 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1779 // copy the next paragraph to this one
1780 LyXParagraph * the_next = Next();
1782 LyXParagraph * firstpar = FirstPhysicalPar();
1785 // first the DTP-stuff
1787 firstpar->line_bottom = the_next->line_bottom;
1788 firstpar->added_space_bottom = the_next->added_space_bottom;
1789 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1791 line_bottom = the_next->line_bottom;
1792 added_space_bottom = the_next->added_space_bottom;
1793 pagebreak_bottom = the_next->pagebreak_bottom;
1796 size_type pos_end = the_next->text.size() - 1;
1797 size_type pos_insert = Last();
1799 // ok, now copy the paragraph
1801 for (i = j = 0; i <= pos_end; ++i) {
1802 the_next->CutIntoMinibuffer(bparams, i);
1803 if (InsertFromMinibuffer(pos_insert + j))
1807 // delete the next paragraph
1808 LyXParagraph * ppar = the_next->previous;
1809 LyXParagraph * npar = the_next->next;
1816 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1818 LyXParagraph * par = ParFromPos(pos);
1820 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1821 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1827 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1829 LyXParagraph * par = ParFromPos(pos);
1831 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1832 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1839 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1841 LyXParagraph const * par = this;
1842 int par_depth = GetDepth();
1844 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1846 textclasslist.Style(bparams.textclass,
1847 layout).endlabeltype;
1848 if (endlabeltype != END_LABEL_NO_LABEL) {
1849 LyXParagraph const * last = this;
1851 if( footnoteflag == NO_FOOTNOTE)
1852 last = LastPhysicalPar();
1853 else if (next->footnoteflag == NO_FOOTNOTE)
1854 return endlabeltype;
1859 if (!last || !last->next)
1860 return endlabeltype;
1862 int next_depth = last->next->GetDepth();
1863 if (par_depth > next_depth ||
1864 (par_depth == next_depth && layout != last->next->GetLayout() ))
1865 return endlabeltype;
1870 par = par->DepthHook(par_depth - 1);
1872 par_depth = par->GetDepth();
1874 return END_LABEL_NO_LABEL;
1878 LyXTextClass::size_type LyXParagraph::GetLayout() const
1881 return FirstPhysicalPar()->layout;
1888 char LyXParagraph::GetDepth() const
1891 return FirstPhysicalPar()->depth;
1898 char LyXParagraph::GetAlign() const
1901 return FirstPhysicalPar()->align;
1908 string const & LyXParagraph::GetLabelstring() const
1911 return FirstPhysicalPar()->labelstring;
1918 int LyXParagraph::GetFirstCounter(int i) const
1921 return FirstPhysicalPar()->counter_[i];
1928 // the next two functions are for the manual labels
1929 string const LyXParagraph::GetLabelWidthString() const
1932 if (!FirstPhysicalPar()->labelwidthstring.empty())
1933 return FirstPhysicalPar()->labelwidthstring;
1935 if (!labelwidthstring.empty())
1936 return labelwidthstring;
1939 return _("Senseless with this layout!");
1943 void LyXParagraph::SetLabelWidthString(string const & s)
1946 LyXParagraph * par = FirstPhysicalPar();
1948 par->labelwidthstring = s;
1950 labelwidthstring = s;
1955 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1956 LyXTextClass::size_type new_layout)
1959 LyXParagraph * par = FirstPhysicalPar();
1961 LyXParagraph * par = this;
1963 LyXParagraph * ppar = 0;
1964 LyXParagraph * npar = 0;
1966 par->layout = new_layout;
1968 /* table stuff -- begin*/
1971 /* table stuff -- end*/
1973 if (par->pextra_type == PEXTRA_NONE) {
1974 if (par->Previous()) {
1976 ppar = par->Previous()->FirstPhysicalPar();
1978 ppar = par->Previous();
1982 && (ppar->depth > par->depth))
1984 ppar = ppar->Previous()->FirstPhysicalPar();
1986 ppar = ppar->Previous();
1991 npar = par->Next()->NextAfterFootnote();
1997 && (npar->depth > par->depth))
1999 npar = npar->Next()->NextAfterFootnote();
2001 npar = npar->Next();
2004 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2006 p1 = ppar->pextra_width,
2007 p2 = ppar->pextra_widthp;
2008 ppar->SetPExtraType(bparams, ppar->pextra_type,
2009 p1.c_str(), p2.c_str());
2011 if ((par->pextra_type == PEXTRA_NONE) &&
2012 npar && (npar->pextra_type != PEXTRA_NONE)) {
2014 p1 = npar->pextra_width,
2015 p2 = npar->pextra_widthp;
2016 npar->SetPExtraType(bparams, npar->pextra_type,
2017 p1.c_str(), p2.c_str());
2023 void LyXParagraph::SetLayout(BufferParams const & bparams,
2024 LyXTextClass::size_type new_layout)
2028 * par = FirstPhysicalPar(),
2035 par->layout = new_layout;
2036 par->labelwidthstring.erase();
2037 par->align = LYX_ALIGN_LAYOUT;
2038 par->added_space_top = VSpace(VSpace::NONE);
2039 par->added_space_bottom = VSpace(VSpace::NONE);
2040 par->spacing.set(Spacing::Default);
2043 /* table stuff -- begin*/
2046 /* table stuff -- end*/
2048 if (par->pextra_type == PEXTRA_NONE) {
2049 if (par->Previous()) {
2051 ppar = par->Previous()->FirstPhysicalPar();
2053 ppar = par->Previous();
2057 && (ppar->depth > par->depth))
2059 ppar = ppar->Previous()->FirstPhysicalPar();
2061 ppar = ppar->Previous();
2066 npar = par->Next()->NextAfterFootnote();
2072 && (npar->depth > par->depth))
2074 npar = npar->Next()->NextAfterFootnote();
2076 npar = npar->Next();
2079 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2081 p1 = ppar->pextra_width,
2082 p2 = ppar->pextra_widthp;
2083 ppar->SetPExtraType(bparams, ppar->pextra_type,
2084 p1.c_str(), p2.c_str());
2086 if ((par->pextra_type == PEXTRA_NONE) &&
2087 npar && (npar->pextra_type != PEXTRA_NONE)) {
2089 p1 = npar->pextra_width,
2090 p2 = npar->pextra_widthp;
2091 npar->SetPExtraType(bparams, npar->pextra_type,
2092 p1.c_str(), p2.c_str());
2098 // if the layout of a paragraph contains a manual label, the beginning of the
2099 // main body is the beginning of the second word. This is what the par-
2100 // function returns. If the layout does not contain a label, the main
2101 // body always starts with position 0. This differentiation is necessary,
2102 // because there cannot be a newline or a blank <= the beginning of the
2103 // main body in TeX.
2105 int LyXParagraph::BeginningOfMainBody() const
2108 if (FirstPhysicalPar() != this)
2111 // Unroll the first two cycles of the loop
2112 // and remember the previous character to
2113 // remove unnecessary GetChar() calls
2116 && GetChar(i) != LyXParagraph::META_NEWLINE
2119 char previous_char = 0, temp = 0;
2121 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2122 // Yes, this ^ is supposed to be "= " not "=="
2125 && previous_char != ' '
2126 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2128 previous_char = temp;
2134 if (i == 0 && i == size() &&
2135 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2136 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2137 ++i; /* the cursor should not jump
2138 * to the main body if there
2145 LyXParagraph * LyXParagraph::DepthHook(int deth)
2147 LyXParagraph * newpar = this;
2153 newpar = newpar->FirstPhysicalPar()->Previous();
2155 newpar = newpar->Previous();
2157 } while (newpar && newpar->GetDepth() > deth
2159 && newpar->footnoteflag == footnoteflag
2164 if (Previous() || GetDepth())
2165 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2170 return newpar->FirstPhysicalPar();
2177 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2179 LyXParagraph const * newpar = this;
2185 newpar = newpar->FirstPhysicalPar()->Previous();
2187 newpar = newpar->Previous();
2189 } while (newpar && newpar->GetDepth() > deth
2191 && newpar->footnoteflag == footnoteflag
2196 if (Previous() || GetDepth())
2197 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2202 return newpar->FirstPhysicalPar();
2209 int LyXParagraph::AutoDeleteInsets()
2212 InsetList::size_type index = 0;
2213 while (index < insetlist.size()) {
2214 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2215 Erase(insetlist[index].pos);
2216 // Erase() calls to insetlist.erase(&insetlist[index])
2217 // so index shouldn't be increased.
2226 LyXParagraph::inset_iterator
2227 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2229 InsetTable search_inset(pos, 0);
2230 InsetList::iterator it = lower_bound(insetlist.begin(),
2232 search_inset, matchIT());
2233 return inset_iterator(it);
2237 // returns -1 if inset not found
2238 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2241 for (InsetList::const_iterator cit = insetlist.begin();
2242 cit != insetlist.end(); ++cit) {
2243 if ((*cit).inset == inset) {
2248 // Think about footnotes.
2249 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2250 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2252 NextAfterFootnote()->GetPositionOfInset(inset);
2254 return text.size() + 1 + further;
2261 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2262 BufferParams const & bparams,
2263 ostream & os, TexRow & texrow,
2268 TexRow & foot_texrow,
2273 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2274 LyXLayout const & style =
2275 textclasslist.Style(bparams.textclass,
2278 bool further_blank_line = false;
2281 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2284 if (start_of_appendix) {
2285 os << "\\appendix\n";
2289 if (!spacing.isDefault()
2290 && (!Previous() || !Previous()->HasSameLayout(this))) {
2291 os << spacing.writeEnvirBegin() << "\n";
2295 if (tex_code_break_column && style.isCommand()){
2300 if (pagebreak_top) {
2302 further_blank_line = true;
2304 if (added_space_top.kind() != VSpace::NONE) {
2305 os << added_space_top.asLatexCommand(bparams);
2306 further_blank_line = true;
2310 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2311 << "\\vspace{-1\\parskip}";
2312 further_blank_line = true;
2315 if (further_blank_line){
2320 Language const * language = getParLanguage(bparams);
2321 Language const * doc_language = bparams.language_info;
2322 Language const * previous_language = previous
2323 ? previous->getParLanguage(bparams) : doc_language;
2324 if (language != doc_language && language != previous_language) {
2325 os << subst(lyxrc.language_command_begin, "$$lang",
2331 if (bparams.inputenc == "auto" &&
2332 language->encoding() != previous_language->encoding()) {
2333 os << "\\inputencoding{"
2334 << language->encoding()->LatexName()
2339 switch (style.latextype) {
2342 << style.latexname()
2343 << style.latexparam();
2345 case LATEX_ITEM_ENVIRONMENT:
2347 bibkey->Latex(buf, os, false, false);
2351 case LATEX_LIST_ENVIRONMENT:
2358 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2360 LyXParagraph * par = next;
2362 // Spit out footnotes
2363 if (lyxrc.rtl_support) {
2364 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2365 && next->footnoteflag != footnoteflag) {
2366 LyXParagraph * p = 0;
2367 bool is_rtl = (size() > 0)
2368 ? GetFontSettings(bparams,
2369 size()-1).isRightToLeft()
2370 : language->RightToLeft();
2371 if ( (p = NextAfterFootnote()) != 0 &&
2373 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2374 is_rtl = getParLanguage(bparams)->RightToLeft();
2375 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2376 && par->footnoteflag != footnoteflag) {
2377 par = par->TeXFootnote(buf, bparams,
2379 foot_texrow, foot_count,
2381 par->SimpleTeXOnePar(buf, bparams,
2382 os, texrow, moving_arg);
2383 is_rtl = (par->size() > 0)
2384 ? par->GetFontSettings(bparams,
2385 par->size()-1).isRightToLeft()
2386 : language->RightToLeft();
2388 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2389 (p = par->NextAfterFootnote()) != 0 &&
2391 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2392 is_rtl = language->RightToLeft();
2397 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2398 && par->footnoteflag != footnoteflag) {
2399 par = par->TeXFootnote(buf, bparams,
2401 foot, foot_texrow, foot_count,
2403 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2409 // Make sure that \\par is done with the font of the last
2410 // character if this has another size as the default.
2411 // This is necessary because LaTeX (and LyX on the screen)
2412 // calculates the space between the baselines according
2413 // to this font. (Matthias)
2414 LyXFont font = getFont(bparams, Last() - 1);
2415 if (need_par && next) {
2416 if (style.resfont.size() != font.size()) {
2422 } else if (textclasslist.Style(bparams.textclass,
2423 GetLayout()).isCommand()) {
2424 if (style.resfont.size() != font.size()) {
2430 } else if ((style.resfont.size() != font.size()) && next){
2431 os << "{\\" << font.latexSize() << " \\par}";
2434 if (language != doc_language &&
2437 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2439 || par->getParLanguage(bparams) != language)) {
2441 << subst(lyxrc.language_command_end, "$$lang",
2442 doc_language->lang());
2445 switch (style.latextype) {
2446 case LATEX_ITEM_ENVIRONMENT:
2447 case LATEX_LIST_ENVIRONMENT:
2448 if (par && (depth < par->depth)) {
2453 case LATEX_ENVIRONMENT:
2454 // if its the last paragraph of the current environment
2455 // skip it otherwise fall through
2457 && (par->layout != layout
2458 || par->depth != depth
2459 || par->pextra_type != pextra_type))
2462 // we don't need it for the last paragraph!!!
2465 && !( footnoteflag != LyXParagraph::NO_FOOTNOTE
2466 && footnotekind != LyXParagraph::FOOTNOTE
2467 && footnotekind != LyXParagraph::MARGIN)
2475 // don't insert this if we would be adding it
2476 // before or after a table in a float. This
2477 // little trick is needed in order to allow
2478 // use of tables in \subfigures or \subtables.
2484 further_blank_line = false;
2486 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2487 further_blank_line = true;
2490 if (added_space_bottom.kind() != VSpace::NONE) {
2491 os << added_space_bottom.asLatexCommand(bparams);
2492 further_blank_line = true;
2495 if (pagebreak_bottom) {
2497 further_blank_line = true;
2500 if (further_blank_line){
2505 if (!spacing.isDefault()
2506 && (!par || !par->HasSameLayout(this))) {
2507 os << spacing.writeEnvirEnd() << "\n";
2511 // we don't need it for the last paragraph!!!
2514 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2515 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2522 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2527 // This one spits out the text of the paragraph
2528 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2529 BufferParams const & bparams,
2530 ostream & os, TexRow & texrow,
2533 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2537 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2540 bool return_value = false;
2542 LyXLayout const & style =
2543 textclasslist.Style(bparams.textclass,
2545 LyXFont basefont, last_font;
2547 // Maybe we have to create a optional argument.
2548 size_type main_body;
2549 if (style.labeltype != LABEL_MANUAL)
2552 main_body = BeginningOfMainBody();
2554 if (main_body > 0) {
2556 basefont = getFont(bparams, -2); // Get label font
2558 basefont = getFont(bparams, -1); // Get layout font
2569 if (style.isCommand()) {
2572 } else if (align != LYX_ALIGN_LAYOUT) {
2575 return_value = true;
2579 moving_arg |= style.needprotect;
2581 // Which font is currently active?
2582 LyXFont running_font(basefont);
2583 // Do we have an open font change?
2584 bool open_font = false;
2586 texrow.start(this, 0);
2588 for (size_type i = 0; i < size(); ++i) {
2590 // First char in paragraph or after label?
2596 if (main_body > 0) {
2598 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2601 basefont = getFont(bparams, -1); // Now use the layout font
2602 running_font = basefont;
2606 if (style.isCommand()) {
2609 } else if (align != LYX_ALIGN_LAYOUT) {
2612 return_value = true;
2616 os << "\\noindent ";
2620 case LYX_ALIGN_NONE:
2621 case LYX_ALIGN_BLOCK:
2622 case LYX_ALIGN_LAYOUT:
2623 case LYX_ALIGN_SPECIAL:
2625 case LYX_ALIGN_LEFT:
2626 if (getParLanguage(bparams)->lang() != "hebrew") {
2627 os << "\\raggedright ";
2630 os << "\\raggedleft ";
2634 case LYX_ALIGN_RIGHT:
2635 if (getParLanguage(bparams)->lang() != "hebrew") {
2636 os << "\\raggedleft ";
2639 os << "\\raggedright ";
2643 case LYX_ALIGN_CENTER:
2644 os << "\\centering ";
2650 value_type c = GetChar(i);
2652 // Fully instantiated font
2653 LyXFont font = getFont(bparams, i);
2655 LyXParagraph * p = 0;
2658 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2659 (p = PreviousBeforeFootnote()) != 0)
2660 last_font = p->getFont(bparams, p->size() - 1);
2663 last_font = running_font;
2665 // Spaces at end of font change are simulated to be
2666 // outside font change, i.e. we write "\textXX{text} "
2667 // rather than "\textXX{text }". (Asger)
2668 if (open_font && c == ' ' && i <= size() - 2
2669 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2670 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2671 font = getFont(bparams, i + 1);
2673 // We end font definition before blanks
2674 if (!font.equalExceptLatex(running_font) && open_font) {
2675 column += running_font.latexWriteEndChanges(os,
2677 (i == main_body-1) ? basefont : font);
2678 running_font = basefont;
2682 // Blanks are printed before start of fontswitch
2684 // Do not print the separation of the optional argument
2685 if (i != main_body - 1) {
2686 SimpleTeXBlanks(os, texrow, i,
2687 column, font, style);
2691 // Do we need to change font?
2692 if (!font.equalExceptLatex(running_font)
2693 && i != main_body-1) {
2694 column += font.latexWriteStartChanges(os, basefont,
2696 running_font = font;
2700 if (c == LyXParagraph::META_NEWLINE) {
2701 // newlines are handled differently here than
2702 // the default in SimpleTeXSpecialChars().
2703 if (!style.newline_allowed
2704 || font.latex() == LyXFont::ON) {
2708 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2711 basefont = getFont(bparams, -1);
2712 running_font = basefont;
2713 if (font.family() ==
2714 LyXFont::TYPEWRITER_FAMILY) {
2722 texrow.start(this, i + 1);
2725 SimpleTeXSpecialChars(buf, bparams,
2726 os, texrow, moving_arg,
2727 font, running_font, basefont,
2728 open_font, style, i, column, c);
2732 // If we have an open font definition, we have to close it
2734 LyXParagraph * p = 0;
2737 && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2738 && (p = NextAfterFootnote()) != 0
2743 running_font.latexWriteEndChanges(os, basefont,
2744 p->getFont(bparams, 0));
2746 running_font.latexWriteEndChanges(os, basefont, basefont);
2749 // Needed if there is an optional argument but no contents.
2750 if (main_body > 0 && main_body == size()) {
2752 return_value = false;
2755 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2756 return return_value;
2761 // This one spits out the text of a table paragraph
2762 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2763 BufferParams const & bparams,
2764 ostream & os, TexRow & texrow)
2766 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2768 bool return_value = false;
2770 LyXLayout const & style =
2771 textclasslist.Style(bparams.textclass, GetLayout());
2775 if (!IsDummy()) { // it is dummy if it is in a float!!!
2777 if (style.isCommand()) {
2780 } else if (align != LYX_ALIGN_LAYOUT) {
2783 return_value = true;
2786 os << "\\noindent ";
2790 case LYX_ALIGN_NONE:
2791 case LYX_ALIGN_BLOCK:
2792 case LYX_ALIGN_LAYOUT:
2793 case LYX_ALIGN_SPECIAL: break;
2794 case LYX_ALIGN_LEFT:
2795 os << "\\raggedright ";
2798 case LYX_ALIGN_RIGHT:
2799 os << "\\raggedleft ";
2802 case LYX_ALIGN_CENTER:
2803 os << "\\centering ";
2811 LyXFont basefont = getFont(bparams, -1); // Get layout font
2812 // Which font is currently active?
2813 LyXFont running_font = basefont;
2815 // Do we have an open font change?
2816 bool open_font = false;
2817 int current_cell_number = -1;
2818 int tmp = table->TexEndOfCell(os, current_cell_number);
2819 for (; tmp > 0 ; --tmp)
2822 texrow.start(this, 0);
2824 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2825 bool first_in_cell = true;
2827 for (size_type i = 0; i < size(); ++i) {
2828 value_type c = GetChar(i);
2829 if (table->IsContRow(current_cell_number + 1)) {
2830 if (c == LyXParagraph::META_NEWLINE)
2831 ++current_cell_number;
2836 if (first_in_cell && is_rtl) {
2839 first_in_cell = false;
2842 // Fully instantiated font
2843 LyXFont font = getFont(bparams, i);
2844 last_font = running_font;
2846 // Spaces at end of font change are simulated to be
2847 // outside font change.
2848 // i.e. we write "\textXX{text} " rather than
2849 // "\textXX{text }". (Asger)
2850 if (open_font && c == ' ' && i <= size() - 2
2851 && getFont(bparams, i + 1) != running_font
2852 && getFont(bparams, i + 1) != font) {
2853 font = getFont(bparams, i + 1);
2856 // We end font definition before blanks
2857 if (font != running_font && open_font) {
2858 column += running_font.latexWriteEndChanges(os,
2861 running_font = basefont;
2864 // Blanks are printed before start of fontswitch
2866 SimpleTeXBlanks(os, texrow, i, column, font, style);
2868 // Do we need to change font?
2869 if (font != running_font) {
2870 column += font.latexWriteStartChanges(os, basefont,
2872 running_font = font;
2875 // Do we need to turn on LaTeX mode?
2876 if (font.latex() != running_font.latex()) {
2877 if (font.latex() == LyXFont::ON
2878 && style.needprotect) {
2883 if (c == LyXParagraph::META_NEWLINE) {
2884 // special case for inside a table
2885 // different from default case in
2886 // SimpleTeXSpecialChars()
2888 column += running_font
2889 .latexWriteEndChanges(os, basefont,
2893 basefont = getFont(bparams, -1);
2894 running_font = basefont;
2895 ++current_cell_number;
2896 if (table->CellHasContRow(current_cell_number) >= 0) {
2897 TeXContTableRows(buf, bparams, os, i + 1,
2898 current_cell_number,
2901 if (is_rtl && !first_in_cell) {
2903 first_in_cell = true;
2906 // if this cell follow only ContRows till end don't
2907 // put the EndOfCell because it is put after the
2909 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2910 --current_cell_number;
2913 int tmp = table->TexEndOfCell(os,
2914 current_cell_number);
2917 } else if (tmp < 0) {
2923 texrow.start(this, i + 1);
2925 SimpleTeXSpecialChars(buf, bparams,
2927 font, running_font, basefont,
2928 open_font, style, i, column, c);
2932 // If we have an open font definition, we have to close it
2934 running_font.latexWriteEndChanges(os, basefont, basefont);
2936 ++current_cell_number;
2937 if (is_rtl && !first_in_cell)
2939 tmp = table->TexEndOfCell(os, current_cell_number);
2940 for (; tmp > 0; --tmp)
2942 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2943 return return_value;
2949 // This one spits out the text off ContRows in tables
2950 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2951 BufferParams const & bparams,
2953 LyXParagraph::size_type i,
2954 int current_cell_number,
2955 int & column, TexRow & texrow)
2957 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2961 bool return_value = false;
2962 LyXLayout const & style =
2963 textclasslist.Style(bparams.textclass,
2965 LyXFont basefont = getFont(bparams, -1); // Get layout font
2967 // Which font is currently active?
2968 LyXFont running_font = basefont;
2969 // Do we have an open font change?
2970 bool open_font = false;
2972 size_type lastpos = i;
2973 int cell = table->CellHasContRow(current_cell_number);
2974 ++current_cell_number;
2977 // first find the right position
2979 for (; (i < size()) && (current_cell_number < cell); ++i) {
2981 if (c == LyXParagraph::META_NEWLINE)
2982 ++current_cell_number;
2986 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2990 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2995 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2999 // Fully instantiated font
3000 LyXFont font = getFont(bparams, i);
3001 last_font = running_font;
3003 // Spaces at end of font change are simulated to
3004 // be outside font change. i.e. we write
3005 // "\textXX{text} " rather than "\textXX{text }".
3007 if (open_font && c == ' ' && i <= size() - 2
3008 && getFont(bparams, i + 1) != running_font
3009 && getFont(bparams, i + 1) != font) {
3010 font = getFont(bparams, i + 1);
3013 // We end font definition before blanks
3014 if (font != running_font && open_font) {
3015 column += running_font.latexWriteEndChanges(os, basefont, font);
3016 running_font = basefont;
3019 // Blanks are printed before start of fontswitch
3021 SimpleTeXBlanks(os, texrow, i,
3022 column, font, style);
3024 // Do we need to change font?
3025 if (font != running_font) {
3027 font.latexWriteStartChanges(os,
3030 running_font = font;
3033 // Do we need to turn on LaTeX mode?
3034 if (font.latex() != running_font.latex()) {
3035 if (font.latex() == LyXFont::ON
3036 && style.needprotect) {
3041 SimpleTeXSpecialChars(buf, bparams,
3042 os, texrow, false, font,
3043 running_font, basefont,
3044 open_font, style, i, column, c);
3046 // If we have an open font definition, we have to close it
3048 running_font.latexWriteEndChanges(os, basefont,
3052 basefont = getFont(bparams, -1);
3053 running_font = basefont;
3054 cell = table->CellHasContRow(current_cell_number);
3056 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
3057 return return_value;
3062 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
3064 bool retval = false;
3066 case LyXParagraph::META_HFILL:
3067 sgml_string.erase();
3069 case LyXParagraph::META_NEWLINE:
3073 sgml_string = "&";
3076 sgml_string = "<";
3079 sgml_string = ">";
3082 sgml_string = "$";
3085 sgml_string = "#";
3088 sgml_string = "%";
3091 sgml_string = "[";
3094 sgml_string = "]";
3097 sgml_string = "{";
3100 sgml_string = "}";
3103 sgml_string = "˜";
3106 sgml_string = """;
3109 sgml_string = "\";
3115 case '\0': // Ignore :-)
3116 sgml_string.erase();
3127 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
3128 ostream & os, string & extra,
3129 int & desc_on, int depth)
3131 BufferParams const & bparams = buffer->params;
3133 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
3135 LyXFont font1, font2;
3138 size_type main_body;
3139 bool emph_flag = false;
3141 LyXLayout const & style =
3142 textclasslist.Style(bparams.textclass,
3145 if (style.labeltype != LABEL_MANUAL)
3148 main_body = BeginningOfMainBody();
3150 // Gets paragraph main font.
3152 font1 = style.labelfont;
3156 int char_line_count = depth;
3157 os << newlineAndDepth(depth);
3159 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3160 os << "<INFORMALTABLE>"
3161 << newlineAndDepth(++depth);
3164 os << "<INFORMALTABLE>"
3165 << newlineAndDepth(++depth);
3167 int current_cell_number = -1;
3168 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3170 // Parsing main loop.
3171 for (size_type i = 0; i < size(); ++i) {
3173 if (table->IsContRow(current_cell_number+1)) {
3174 if (c == LyXParagraph::META_NEWLINE)
3175 ++current_cell_number;
3180 // Fully instantiated font
3181 font2 = getFont(bparams, i);
3183 // Handle <emphasis> tag.
3184 if (font1.emph() != font2.emph() && i) {
3185 if (font2.emph() == LyXFont::ON) {
3188 } else if (emph_flag) {
3189 os << "</emphasis>";
3193 if (c == LyXParagraph::META_NEWLINE) {
3194 // We have only to control for emphasis open here!
3196 os << "</emphasis>";
3199 font1 = font2 = getFont(bparams, -1);
3200 ++current_cell_number;
3201 if (table->CellHasContRow(current_cell_number) >= 0) {
3202 DocBookContTableRows(buffer,
3203 os, extra, desc_on, i + 1,
3204 current_cell_number,
3207 // if this cell follow only ContRows till end don't
3208 // put the EndOfCell because it is put after the
3210 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3211 --current_cell_number;
3214 tmp = table->DocBookEndOfCell(os,
3215 current_cell_number,
3220 } else if (c == LyXParagraph::META_INSET) {
3221 inset = GetInset(i);
3222 std::ostringstream ost;
3223 inset->DocBook(buffer, ost);
3224 string tmp_out = ost.str().c_str();
3227 // This code needs some explanation:
3228 // Two insets are treated specially
3229 // label if it is the first element in a
3230 // command paragraph
3232 // graphics inside tables or figure floats
3234 // title (the equivalente in latex for this
3236 // and title should come first
3239 if(desc_on != 3 || i != 0) {
3240 if(tmp_out[0] == '@') {
3242 extra += frontStrip(tmp_out,
3245 os << frontStrip(tmp_out,
3250 } else if (font2.latex() == LyXFont::ON) {
3251 // "TeX"-Mode on == > SGML-Mode on.
3257 if (linuxDocConvertChar(c, sgml_string)
3258 && !style.free_spacing) {
3259 // in freespacing mode, spaces are
3260 // non-breaking characters
3265 << "</term><listitem><para>";
3277 // Needed if there is an optional argument but no contents.
3278 if (main_body > 0 && main_body == size()) {
3283 os << "</emphasis>";
3286 ++current_cell_number;
3287 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3288 // Resets description flag correctly.
3291 // <term> not closed...
3296 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3298 os << "</INFORMALTABLE>";
3300 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3307 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3308 ostream & os, string & extra,
3310 LyXParagraph::size_type i,
3311 int current_cell_number, int &column)
3316 BufferParams const & bparams = buffer->params;
3318 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3323 //string emph = "emphasis";
3324 bool emph_flag = false;
3325 int char_line_count = 0;
3327 LyXLayout const & style =
3328 textclasslist.Style(bparams.textclass,
3331 size_type main_body;
3332 if (style.labeltype != LABEL_MANUAL)
3335 main_body = BeginningOfMainBody();
3337 // Gets paragraph main font.
3340 font1 = style.labelfont;
3344 size_type lastpos = i;
3345 int cell = table->CellHasContRow(current_cell_number);
3346 ++current_cell_number;
3348 // first find the right position
3350 for (; i < size() && current_cell_number < cell; ++i) {
3352 if (c == LyXParagraph::META_NEWLINE)
3353 ++current_cell_number;
3357 // I don't know how to handle this so I comment it
3358 // for the moment (Jug)
3359 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3360 // file += " \\\\\n";
3363 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3368 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3372 // Fully instantiated font
3373 font2 = getFont(bparams, i);
3375 // Handle <emphasis> tag.
3376 if (font1.emph() != font2.emph() && i) {
3377 if (font2.emph() == LyXFont::ON) {
3380 } else if (emph_flag) {
3381 os << "</emphasis>";
3385 if (c == LyXParagraph::META_INSET) {
3386 inset = GetInset(i);
3387 std::ostringstream ost;
3388 inset->DocBook(buffer, ost);
3389 string tmp_out = ost.str().c_str();
3391 // This code needs some explanation:
3392 // Two insets are treated specially
3393 // label if it is the first element in a
3394 // command paragraph
3396 // graphics inside tables or figure floats
3397 // can't go on title (the equivalente in
3398 // latex for this case is caption and title
3399 // should come first
3402 if(desc_on != 3 || i != 0) {
3403 if(tmp_out[0] == '@') {
3405 extra += frontStrip(tmp_out, '@');
3407 os << frontStrip(tmp_out, '@');
3411 } else if (font2.latex() == LyXFont::ON) {
3412 // "TeX"-Mode on == > SGML-Mode on.
3418 if (linuxDocConvertChar(c, sgml_string)
3419 && !style.free_spacing) {
3420 // in freespacing mode, spaces are
3421 // non-breaking characters
3426 << "</term><listitem><para>";
3436 // we have only to control for emphasis open here!
3438 os << "</emphasis>";
3441 font1 = font2 = getFont(bparams, -1);
3442 cell = table->CellHasContRow(current_cell_number);
3444 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3449 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3450 LyXParagraph::size_type const i,
3451 int & column, LyXFont const & font,
3452 LyXLayout const & style)
3454 if (column > tex_code_break_column
3456 && GetChar(i - 1) != ' '
3458 // In LaTeX mode, we don't want to
3459 // break lines since some commands
3461 && ! (font.latex() == LyXFont::ON)
3462 // same in FreeSpacing mode
3463 && !style.free_spacing
3464 // In typewriter mode, we want to avoid
3465 // ! . ? : at the end of a line
3466 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3467 && (GetChar(i-1) == '.'
3468 || GetChar(i-1) == '?'
3469 || GetChar(i-1) == ':'
3470 || GetChar(i-1) == '!'))) {
3471 if (tex_code_break_column == 0) {
3472 // in batchmode we need LaTeX to still
3473 // see it as a space not as an extra '\n'
3479 texrow.start(this, i + 1);
3481 } else if (font.latex() == LyXFont::OFF) {
3482 if (style.free_spacing) {
3491 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3492 BufferParams const & bparams,
3493 ostream & os, TexRow & texrow,
3496 LyXFont & running_font,
3499 LyXLayout const & style,
3500 LyXParagraph::size_type & i,
3502 LyXParagraph::value_type const c)
3504 // Two major modes: LaTeX or plain
3505 // Handle here those cases common to both modes
3506 // and then split to handle the two modes separately.
3508 case LyXParagraph::META_INSET: {
3509 Inset * inset = GetInset(i);
3512 int len = os.tellp();
3513 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3514 || inset->LyxCode() == Inset::MATH_CODE
3515 || inset->LyxCode() == Inset::URL_CODE)
3516 && running_font.isRightToLeft()) {
3521 int tmp = inset->Latex(buf, os, moving_arg,
3522 style.free_spacing);
3530 column += os.tellp() - len;
3539 case LyXParagraph::META_NEWLINE:
3541 column += running_font.latexWriteEndChanges(os,
3546 basefont = getFont(bparams, -1);
3547 running_font = basefont;
3550 case LyXParagraph::META_HFILL:
3556 // And now for the special cases within each mode
3557 // Are we in LaTeX mode?
3558 if (font.latex() == LyXFont::ON) {
3559 // at present we only have one option
3560 // but I'll leave it as a switch statement
3561 // so its simpler to extend. (ARRae)
3564 // make sure that we will not print
3565 // error generating chars to the tex
3566 // file. This test would not be needed
3567 // if it were done in the buffer
3575 // Plain mode (i.e. not LaTeX)
3578 os << "\\textbackslash{}";
3582 case '°': case '±': case '²': case '³':
3583 case '×': case '÷': case '¹': case 'ª':
3584 case 'º': case '¬': case 'µ':
3585 if (bparams.inputenc == "latin1" ||
3586 (bparams.inputenc == "auto" &&
3587 font.language()->encoding()->LatexName()
3589 os << "\\ensuremath{"
3598 case '|': case '<': case '>':
3599 // In T1 encoding, these characters exist
3600 if (lyxrc.fontenc == "T1") {
3602 //... but we should avoid ligatures
3603 if ((c == '>' || c == '<')
3605 && GetChar(i + 1) == c) {
3606 //os << "\\textcompwordmark{}";
3607 // Jean-Marc, have a look at
3608 // this. IÂ think this works
3616 // Typewriter font also has them
3617 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3621 // Otherwise, we use what LaTeX
3625 os << "\\textless{}";
3629 os << "\\textgreater{}";
3633 os << "\\textbar{}";
3639 case '-': // "--" in Typewriter mode -> "-{}-"
3641 && GetChar(i + 1) == '-'
3642 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3651 os << "\\char`\\\"{}";
3656 if (bparams.inputenc == "default") {
3665 case '%': case '#': case '{':
3672 os << "\\textasciitilde{}";
3677 os << "\\textasciicircum{}";
3681 case '*': case '[': case ']':
3682 // avoid being mistaken for optional arguments
3683 os << '{' << c << '}';
3688 // Blanks are printed before font switching.
3689 // Sure? I am not! (try nice-latex)
3690 // I am sure it's correct. LyX might be smarter
3691 // in the future, but for now, nothing wrong is
3696 /* idea for labels --- begin*/
3700 && font.family() != LyXFont::TYPEWRITER_FAMILY
3701 && GetChar(i + 1) == 'y'
3702 && GetChar(i + 2) == 'X') {
3710 && font.family() != LyXFont::TYPEWRITER_FAMILY
3711 && GetChar(i + 1) == 'e'
3712 && GetChar(i + 2) == 'X') {
3717 // Check for "LaTeX2e"
3720 && font.family() != LyXFont::TYPEWRITER_FAMILY
3721 && GetChar(i + 1) == 'a'
3722 && GetChar(i + 2) == 'T'
3723 && GetChar(i + 3) == 'e'
3724 && GetChar(i + 4) == 'X'
3725 && GetChar(i + 5) == '2'
3726 && GetChar(i + 6) == 'e') {
3731 // Check for "LaTeX"
3734 && font.family() != LyXFont::TYPEWRITER_FAMILY
3735 && GetChar(i + 1) == 'a'
3736 && GetChar(i + 2) == 'T'
3737 && GetChar(i + 3) == 'e'
3738 && GetChar(i + 4) == 'X') {
3742 /* idea for labels --- end*/
3743 } else if (c != '\0') {
3753 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3754 BufferParams const & bparams,
3755 ostream & os, TexRow & texrow
3758 TexRow & foot_texrow,
3763 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3764 LyXParagraph * par = this;
3767 (par->depth == depth)
3769 && (par->footnoteflag == footnoteflag)
3774 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3776 if (textclasslist.Style(bparams.textclass,
3777 par->layout).isEnvironment()
3778 || par->pextra_type != PEXTRA_NONE) {
3779 par = par->TeXEnvironment(buf, bparams,
3787 par = par->TeXOnePar(buf, bparams,
3797 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3803 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3804 BufferParams const & bparams,
3805 ostream & os, TexRow & texrow
3808 TexRow & foot_texrow,
3813 bool eindent_open = false;
3815 bool foot_this_level = false;
3817 // flags when footnotetext should be appended to file.
3818 static bool minipage_open = false;
3819 static int minipage_open_depth = 0;
3820 char par_sep = bparams.paragraph_separation;
3822 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3825 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3828 LyXLayout const & style =
3829 textclasslist.Style(bparams.textclass,
3832 if (pextra_type == PEXTRA_INDENT) {
3833 if (!pextra_width.empty()) {
3834 os << "\\begin{LyXParagraphIndent}{"
3835 << pextra_width << "}\n";
3837 //float ib = atof(pextra_widthp.c_str())/100;
3838 // string can't handle floats at present (971109)
3839 // so I'll do a conversion by hand knowing that
3840 // the limits are 0.0 to 1.0. ARRae.
3841 os << "\\begin{LyXParagraphIndent}{";
3842 switch (pextra_widthp.length()) {
3854 os << "\\columnwidth}\n";
3857 eindent_open = true;
3859 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3860 if (pextra_hfill && Previous() &&
3861 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3862 os << "\\hfill{}\n";
3865 if (par_sep == BufferParams::PARSEP_INDENT) {
3866 os << "{\\setlength\\parindent{0pt}\n";
3869 os << "\\begin{minipage}";
3870 switch(pextra_alignment) {
3871 case MINIPAGE_ALIGN_TOP:
3874 case MINIPAGE_ALIGN_MIDDLE:
3877 case MINIPAGE_ALIGN_BOTTOM:
3881 if (!pextra_width.empty()) {
3882 os << '{' << pextra_width << "}\n";
3884 //float ib = atof(par->pextra_width.c_str())/100;
3885 // string can't handle floats at present
3886 // so I'll do a conversion by hand knowing that
3887 // the limits are 0.0 to 1.0. ARRae.
3889 switch (pextra_widthp.length()) {
3901 os << "\\columnwidth}\n";
3904 if (par_sep == BufferParams::PARSEP_INDENT) {
3905 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3908 minipage_open = true;
3909 minipage_open_depth = depth;
3912 #ifdef WITH_WARNINGS
3913 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3914 //I disabled it because it breaks when lists span on several
3917 if (style.isEnvironment()){
3918 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3919 #ifdef FANCY_FOOTNOTE_CODE
3920 if (foot_count < 0) {
3921 // flag that footnote[mark][text] should be
3922 // used for any footnotes from now on
3924 foot_this_level = true;
3927 os << "\\begin{" << style.latexname() << "}{"
3928 << labelwidthstring << "}\n";
3929 } else if (style.labeltype == LABEL_BIBLIO) {
3931 os << "\\begin{" << style.latexname() << "}{"
3932 << bibitemWidest(current_view)
3934 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3935 #ifdef FANCY_FOOTNOTE_CODE
3936 if (foot_count < 0) {
3937 // flag that footnote[mark][text] should be
3938 // used for any footnotes from now on
3940 foot_this_level = true;
3943 os << "\\begin{" << style.latexname() << '}'
3944 << style.latexparam() << '\n';
3946 os << "\\begin{" << style.latexname() << '}'
3947 << style.latexparam() << '\n';
3950 LyXParagraph * par = this;
3952 par = par->TeXOnePar(buf, bparams,
3956 foot, foot_texrow, foot_count
3960 if (minipage_open && par && !style.isEnvironment() &&
3961 (par->pextra_type == PEXTRA_MINIPAGE) &&
3962 par->pextra_start_minipage) {
3963 os << "\\end{minipage}\n";
3965 if (par_sep == BufferParams::PARSEP_INDENT) {
3969 minipage_open = false;
3971 if (par && par->depth > depth) {
3972 if (textclasslist.Style(bparams.textclass,
3973 par->layout).isParagraph()
3978 // How to handle this? (Lgb)
3979 //&& !suffixIs(os, "\n\n")
3981 // There should be at least one '\n' already
3982 // but we need there to be two for Standard
3983 // paragraphs that are depth-increment'ed to be
3984 // output correctly. However, tables can
3985 // also be paragraphs so don't adjust them.
3988 // Will it ever harm to have one '\n' too
3989 // many? i.e. that we sometimes will have
3990 // three in a row. (Lgb)
3994 par = par->TeXDeeper(buf, bparams, os, texrow
3996 ,foot, foot_texrow, foot_count
4000 if (par && par->layout == layout && par->depth == depth &&
4001 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
4002 if (par->pextra_hfill && par->Previous() &&
4003 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
4004 os << "\\hfill{}\n";
4007 if (par_sep == BufferParams::PARSEP_INDENT) {
4008 os << "{\\setlength\\parindent{0pt}\n";
4011 os << "\\begin{minipage}";
4012 switch(par->pextra_alignment) {
4013 case MINIPAGE_ALIGN_TOP:
4016 case MINIPAGE_ALIGN_MIDDLE:
4019 case MINIPAGE_ALIGN_BOTTOM:
4023 if (!par->pextra_width.empty()) {
4024 os << '{' << par->pextra_width << "}\n";
4026 //float ib = atof(par->pextra_widthp.c_str())/100;
4027 // string can't handle floats at present
4028 // so I'll do a conversion by hand knowing that
4029 // the limits are 0.0 to 1.0. ARRae.
4031 switch (par->pextra_widthp.length()) {
4036 os << "0." << par->pextra_widthp;
4039 os << "0.0" << par->pextra_widthp;
4041 os << "\\columnwidth}\n";
4044 if (par_sep == BufferParams::PARSEP_INDENT) {
4045 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
4048 minipage_open = true;
4049 minipage_open_depth = par->depth;
4052 && par->layout == layout
4053 && par->depth == depth
4054 && par->pextra_type == pextra_type
4056 && par->footnoteflag == footnoteflag
4060 if (style.isEnvironment()) {
4061 os << "\\end{" << style.latexname() << '}';
4063 // maybe this should go after the minipage closes?
4064 if (foot_this_level) {
4065 if (foot_count >= 1) {
4066 if (foot_count > 1) {
4067 os << "\\addtocounter{footnote}{-"
4072 texrow += foot_texrow;
4074 foot_texrow.reset();
4080 if (minipage_open && (minipage_open_depth == depth) &&
4081 (!par || par->pextra_start_minipage ||
4082 par->pextra_type != PEXTRA_MINIPAGE)) {
4083 os << "\\end{minipage}\n";
4085 if (par_sep == BufferParams::PARSEP_INDENT) {
4089 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
4090 os << "\\medskip\n\n";
4094 minipage_open = false;
4097 os << "\\end{LyXParagraphIndent}\n";
4100 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
4101 && par->pextra_hfill)) {
4105 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
4106 return par; // ale970302
4111 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
4112 BufferParams const & bparams,
4113 ostream & os, TexRow & texrow,
4114 ostream & foot, TexRow & foot_texrow,
4118 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
4119 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
4120 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4121 "No footnote!" << endl;
4123 LyXParagraph * par = this;
4124 LyXLayout const & style =
4125 textclasslist.Style(bparams.textclass,
4126 previous->GetLayout());
4128 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
4129 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4130 "Float other than footnote in command"
4131 " with moving argument is illegal" << endl;
4134 if (footnotekind != LyXParagraph::FOOTNOTE
4135 && footnotekind != LyXParagraph::MARGIN
4138 // How to solve this?
4139 //&& !suffixIs(file, '\n')
4141 // we need to ensure that real floats like tables and figures
4142 // have their \begin{} on a new line otherwise we can get
4143 // incorrect results when using the endfloat.sty package
4144 // especially if two floats follow one another. ARRae 981022
4145 // NOTE: if the file is length 0 it must have just been
4146 // written out so we assume it ended with a '\n'
4148 // As far as I can see there is never any harm in writing
4149 // a '\n' too much. Please tell me if I am wrong. (Lgb)
4154 bool moving_arg = false;
4155 bool need_closing = false;
4156 bool is_rtl = isRightToLeftPar(bparams);
4158 if (is_rtl != parent_is_rtl) {
4163 need_closing = true;
4166 //BufferParams * params = ¤t_view->buffer()->params;
4167 bool footer_in_body = true;
4168 switch (footnotekind) {
4169 case LyXParagraph::FOOTNOTE:
4170 if (style.intitle) {
4171 os << "\\thanks{\n";
4172 footer_in_body = false;
4175 if (foot_count == -1) {
4176 // we're at depth 0 so we can use:
4177 os << "\\footnote{%\n";
4178 footer_in_body = false;
4180 os << "\\footnotemark{}%\n";
4182 // we only need this when there are
4183 // multiple footnotes
4184 os << "\\stepcounter{footnote}";
4186 os << "\\footnotetext{%\n";
4187 foot_texrow.start(this, 0);
4188 foot_texrow.newline();
4193 case LyXParagraph::MARGIN:
4194 os << "\\marginpar{\n";
4196 case LyXParagraph::FIG:
4197 if (pextra_type == PEXTRA_FLOATFLT
4198 && (!pextra_width.empty()
4199 || !pextra_widthp.empty())) {
4200 if (!pextra_width.empty())
4201 os << "\\begin{floatingfigure}{"
4202 << pextra_width << "}\n";
4204 os << "\\begin{floatingfigure}{"
4205 << atoi(pextra_widthp.c_str())/100.0
4206 << "\\textwidth}\n";
4208 os << "\\begin{figure}";
4209 if (!bparams.float_placement.empty()) {
4210 os << '[' << bparams.float_placement << "]\n";
4216 case LyXParagraph::TAB:
4217 os << "\\begin{table}";
4218 if (!bparams.float_placement.empty()) {
4219 os << '[' << bparams.float_placement << "]\n";
4224 case LyXParagraph::WIDE_FIG:
4225 os << "\\begin{figure*}";
4226 if (!bparams.float_placement.empty()) {
4227 os << '[' << bparams.float_placement << "]\n";
4232 case LyXParagraph::WIDE_TAB:
4233 os << "\\begin{table*}";
4234 if (!bparams.float_placement.empty()) {
4235 os << '[' << bparams.float_placement << "]\n";
4240 case LyXParagraph::ALGORITHM:
4241 os << "\\begin{algorithm}\n";
4246 if (footnotekind != LyXParagraph::FOOTNOTE
4247 || !footer_in_body) {
4248 // Process text for all floats except footnotes in body
4250 LyXLayout const & style =
4252 .Style(bparams.textclass, par->layout);
4254 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4256 if (style.isEnvironment()
4257 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4258 // Allows the use of minipages within float
4259 // environments. Shouldn't be circular because
4260 // we don't support footnotes inside
4261 // floats (yet). ARRae
4262 par = par->TeXEnvironment(buf, bparams, os,
4267 par = par->TeXOnePar(buf, bparams,
4268 os, texrow, moving_arg,
4273 if (par && !par->IsDummy() && par->depth > depth) {
4274 par = par->TeXDeeper(buf, bparams, os, texrow,
4278 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4280 // process footnotes > depth 0 or in environments separately
4281 // NOTE: Currently don't support footnotes within footnotes
4282 // even though that is possible using the \footnotemark
4283 std::ostringstream dummy;
4284 TexRow dummy_texrow;
4285 int dummy_count = 0;
4287 LyXLayout const & style =
4289 .Style(bparams.textclass, par->layout);
4291 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4293 if (style.isEnvironment()
4294 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4295 // Allows the use of minipages within float
4296 // environments. Shouldn't be circular because
4297 // we don't support footnotes inside
4298 // floats (yet). ARRae
4299 par = par->TeXEnvironment(buf, bparams,
4301 dummy, dummy_texrow,
4304 par = par->TeXOnePar(buf, bparams,
4307 dummy, dummy_texrow,
4311 if (par && !par->IsDummy() && par->depth > depth) {
4312 par = par->TeXDeeper(buf, bparams,
4314 dummy, dummy_texrow,
4318 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4320 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4321 "Footnote in a Footnote -- not supported"
4324 //#ifndef HAVE_OSTREAM
4325 // delete [] dummy.str();
4329 switch (footnotekind) {
4330 case LyXParagraph::FOOTNOTE:
4331 if (footer_in_body) {
4332 // This helps tell which of the multiple
4333 // footnotetexts an error was in.
4335 foot_texrow.newline();
4340 case LyXParagraph::MARGIN:
4343 case LyXParagraph::FIG:
4344 if (pextra_type == PEXTRA_FLOATFLT
4345 && (!pextra_width.empty()
4346 || !pextra_widthp.empty()))
4347 os << "\\end{floatingfigure}";
4349 os << "\\end{figure}";
4351 case LyXParagraph::TAB:
4352 os << "\\end{table}";
4354 case LyXParagraph::WIDE_FIG:
4355 os << "\\end{figure*}";
4357 case LyXParagraph::WIDE_TAB:
4358 os << "\\end{table*}";
4360 case LyXParagraph::ALGORITHM:
4361 os << "\\end{algorithm}";
4368 if (footnotekind != LyXParagraph::FOOTNOTE
4369 && footnotekind != LyXParagraph::MARGIN) {
4370 // we need to ensure that real floats like tables and figures
4371 // have their \end{} on a line of their own otherwise we can
4372 // get incorrect results when using the endfloat.sty package.
4377 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4382 bool LyXParagraph::IsDummy() const
4384 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4385 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4389 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4390 int type, string const & width,
4391 string const & widthp)
4394 pextra_width = width;
4395 pextra_widthp = widthp;
4397 if (textclasslist.Style(bparams.textclass,
4398 layout).isEnvironment()) {
4399 LyXParagraph * par = this;
4400 LyXParagraph * ppar = par;
4402 while (par && (par->layout == layout)
4403 && (par->depth == depth)) {
4405 par = par->Previous();
4408 par = par->FirstPhysicalPar();
4410 while (par && par->depth > depth) {
4411 par = par->Previous();
4414 par = par->FirstPhysicalPar();
4419 while (par && (par->layout == layout)
4420 && (par->depth == depth)) {
4421 par->pextra_type = type;
4422 par->pextra_width = width;
4423 par->pextra_widthp = widthp;
4425 par = par->NextAfterFootnote();
4429 if (par && (par->depth > depth))
4430 par->SetPExtraType(bparams,
4431 type, width, widthp);
4433 while (par && ((par->depth > depth) || par->IsDummy()))
4434 par = par->NextAfterFootnote();
4436 while (par && ((par->depth > depth)))
4444 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4446 if (pextra_type == PEXTRA_NONE)
4449 pextra_type = PEXTRA_NONE;
4450 pextra_width.erase();
4451 pextra_widthp.erase();
4453 if (textclasslist.Style(bparams.textclass,
4454 layout).isEnvironment()) {
4455 LyXParagraph * par = this;
4456 LyXParagraph * ppar = par;
4458 while (par && (par->layout == layout)
4459 && (par->depth == depth)) {
4461 par = par->Previous();
4464 par = par->FirstPhysicalPar();
4466 while (par && par->depth > depth) {
4467 par = par->Previous();
4470 par = par->FirstPhysicalPar();
4475 while (par && (par->layout == layout)
4476 && (par->depth == depth)) {
4477 par->pextra_type = PEXTRA_NONE;
4478 par->pextra_width.erase();
4479 par->pextra_widthp.erase();
4481 par = par->NextAfterFootnote();
4485 if (par && (par->depth > depth))
4486 par->UnsetPExtraType(bparams);
4488 while (par && ((par->depth > depth) || par->IsDummy()))
4489 par = par->NextAfterFootnote();
4491 while (par && ((par->depth > depth)))
4499 bool LyXParagraph::IsHfill(size_type pos) const
4501 return IsHfillChar(GetChar(pos));
4505 bool LyXParagraph::IsInset(size_type pos) const
4507 return IsInsetChar(GetChar(pos));
4512 bool LyXParagraph::IsFloat(size_type pos) const
4514 return IsFloatChar(GetChar(pos));
4519 bool LyXParagraph::IsNewline(size_type pos) const
4521 return pos >= 0 && IsNewlineChar(GetChar(pos));
4525 bool LyXParagraph::IsSeparator(size_type pos) const
4527 return IsSeparatorChar(GetChar(pos));
4531 bool LyXParagraph::IsLineSeparator(size_type pos) const
4533 return IsLineSeparatorChar(GetChar(pos));
4537 bool LyXParagraph::IsKomma(size_type pos) const
4539 return IsKommaChar(GetChar(pos));
4543 /// Used by the spellchecker
4544 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4546 value_type c = GetChar(pos);
4547 if (IsLetterChar(c))
4549 // '\0' is not a letter, allthough every string contains "" (below)
4552 // We want to pass the ' and escape chars to ispell
4553 string extra = lyxrc.isp_esc_chars + '\'';
4554 char ch[2] = { c, 0 };
4555 return contains(extra, ch);
4559 bool LyXParagraph::IsWord(size_type pos ) const
4561 return IsWordChar(GetChar(pos)) ;
4566 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4570 return FirstPhysicalPar()->getParLanguage(bparams);
4574 Language const * lang = 0;
4578 lang = GetFirstFontSettings().language();
4581 for (size_type pos = 0; pos < size(); ++pos) {
4582 if (IsNewline(pos)) {
4583 lang = GetFontSettings(bparams, pos).language();
4588 lang = GetFirstFontSettings().language();
4591 if (lang->lang() == "default")
4592 return bparams.language_info;
4594 } else if (previous)
4595 return previous->getParLanguage(bparams);
4597 return bparams.language_info;
4601 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4603 return lyxrc.rtl_support
4607 && getParLanguage(bparams)->RightToLeft();
4611 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4612 Language const * from, Language const * to)
4614 for(size_type i = 0; i < size(); ++i) {
4615 LyXFont font = GetFontSettings(bparams, i);
4616 if (font.language() == from) {
4617 font.setLanguage(to);
4624 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4626 Language const * doc_language = bparams.language_info;
4627 for (FontList::const_iterator cit = fontlist.begin();
4628 cit != fontlist.end(); ++cit)
4629 if ((*cit).font.language() != doc_language)
4635 // Convert the paragraph to a string.
4636 // Used for building the table of contents
4637 string const LyXParagraph::String(Buffer const * buffer, bool label)
4639 BufferParams const & bparams = buffer->params;
4642 if (label && !IsDummy() && !labelstring.empty())
4644 if (label && !labelstring.empty())
4646 s += labelstring + ' ';
4647 string::size_type len = s.size();
4649 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4650 value_type c = GetChar(i);
4653 else if (c == META_INSET &&
4654 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4655 std::ostringstream ost;
4656 GetInset(i)->Ascii(buffer, ost);
4657 s += subst(ost.str(),'\n',' ');
4662 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4663 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4664 s += NextAfterFootnote()->String(buffer, false);
4668 if (isRightToLeftPar(bparams))
4669 reverse(s.begin() + len,s.end());
4677 string const LyXParagraph::String(Buffer const * buffer,
4678 LyXParagraph::size_type beg,
4679 LyXParagraph::size_type end)
4686 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4688 if (cell >= table->NumberOfCellsInRow(actcell))
4697 if (beg == 0 && !IsDummy() && !labelstring.empty())
4699 if (beg == 0 && !labelstring.empty())
4701 s += labelstring + ' ';
4703 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4704 value_type c = GetChar(i);
4707 else if (c == META_INSET) {
4708 std::ostringstream ost;
4709 GetInset(i)->Ascii(buffer, ost);
4713 else if (table && IsNewlineChar(c)) {
4714 if (cell >= table->NumberOfCellsInRow(actcell)) {
4730 void LyXParagraph::SetInsetOwner(Inset *i)
4733 for (InsetList::const_iterator cit = insetlist.begin();
4734 cit != insetlist.end(); ++cit) {
4736 (*cit).inset->setOwner(i);
4741 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4744 for (InsetList::const_iterator cit = insetlist.begin();
4745 cit != insetlist.end(); ++cit) {
4747 if ((*cit).inset->IsTextInset()) {
4748 static_cast<UpdatableInset *>
4749 ((*cit).inset)->deleteLyXText(bv);
4756 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4759 for (InsetList::const_iterator cit = insetlist.begin();
4760 cit != insetlist.end(); ++cit) {
4762 if ((*cit).inset->IsTextInset()) {
4763 static_cast<UpdatableInset *>
4764 ((*cit).inset)->resizeLyXText(bv);