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 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 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 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 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;
1654 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1657 // copy everything behind the break-position to the new paragraph
1659 result->text = text;
1660 result->fontlist = fontlist;
1661 result->insetlist = insetlist;
1662 for (InsetList::iterator it = result->insetlist.begin();
1663 it != result->insetlist.end(); ++it)
1664 (*it).inset = (*it).inset->Clone();
1669 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1672 par = par->FirstPhysicalPar();
1677 par->footnoteflag == footnoteflag &&
1678 par->footnotekind == footnotekind &&
1680 par->layout == layout &&
1682 par->align == align &&
1684 par->line_bottom == line_bottom &&
1685 par->pagebreak_bottom == pagebreak_bottom &&
1686 par->added_space_bottom == added_space_bottom &&
1688 par->line_top == line_top &&
1689 par->pagebreak_top == pagebreak_top &&
1690 par->added_space_top == added_space_top &&
1692 par->spacing == spacing &&
1694 par->pextra_type == pextra_type &&
1695 par->pextra_width == pextra_width &&
1696 par->pextra_widthp == pextra_widthp &&
1697 par->pextra_alignment == pextra_alignment &&
1698 par->pextra_hfill == pextra_hfill &&
1699 par->pextra_start_minipage == pextra_start_minipage &&
1701 par->table == table && // what means: NO TABLE AT ALL
1704 par->noindent == noindent &&
1705 par->depth == depth);
1709 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1710 LyXParagraph::size_type pos)
1713 // create a new paragraph
1714 LyXParagraph * par = ParFromPos(pos);
1716 LyXParagraph * tmp = new LyXParagraph(par);
1718 tmp->MakeSameLayout(par);
1720 // When can pos < Last()?
1721 // I guess pos == Last() is possible.
1723 // copy everything behind the break-position to the new
1725 size_type pos_first = 0;
1726 while (ParFromPos(pos_first) != par)
1728 size_type pos_end = pos_first + par->text.size() - 1;
1731 for (i = j = pos; i <= pos_end; ++i) {
1732 par->CutIntoMinibuffer(bparams, i - pos_first);
1733 if (tmp->InsertFromMinibuffer(j - pos))
1736 tmp->text.resize(tmp->text.size());
1737 for (size_type i = pos_end; i >= pos; --i)
1738 par->Erase(i - pos_first);
1740 par->text.resize(par->text.size());
1743 // create a new paragraph
1744 LyXParagraph * tmp = new LyXParagraph(this);
1745 tmp->MakeSameLayout(this);
1747 // When can pos > Last()?
1748 // I guess pos == Last() is possible.
1750 // copy everything behind the break-position to the new
1752 size_type pos_end = text.size() - 1;
1755 for (i = j = pos; i <= pos_end; ++i) {
1756 CutIntoMinibuffer(bparams, i);
1757 if (tmp->InsertFromMinibuffer(j - pos))
1763 for (size_type i = pos_end; i >= pos; --i)
1772 // Be carefull, this does not make any check at all.
1773 // This method has wrong name, it combined this par with the next par.
1774 // In that sense it is the reverse of break paragraph. (Lgb)
1775 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1777 // copy the next paragraph to this one
1778 LyXParagraph * the_next = Next();
1780 LyXParagraph * firstpar = FirstPhysicalPar();
1783 // first the DTP-stuff
1785 firstpar->line_bottom = the_next->line_bottom;
1786 firstpar->added_space_bottom = the_next->added_space_bottom;
1787 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1789 line_bottom = the_next->line_bottom;
1790 added_space_bottom = the_next->added_space_bottom;
1791 pagebreak_bottom = the_next->pagebreak_bottom;
1794 size_type pos_end = the_next->text.size() - 1;
1795 size_type pos_insert = Last();
1797 // ok, now copy the paragraph
1799 for (i = j = 0; i <= pos_end; ++i) {
1800 the_next->CutIntoMinibuffer(bparams, i);
1801 if (InsertFromMinibuffer(pos_insert + j))
1805 // delete the next paragraph
1806 LyXParagraph * ppar = the_next->previous;
1807 LyXParagraph * npar = the_next->next;
1814 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1816 LyXParagraph * par = ParFromPos(pos);
1818 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1819 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1825 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1827 LyXParagraph * par = ParFromPos(pos);
1829 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1830 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1837 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1839 LyXParagraph const * par = this;
1840 int par_depth = GetDepth();
1842 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1844 textclasslist.Style(bparams.textclass,
1845 layout).endlabeltype;
1846 if (endlabeltype != END_LABEL_NO_LABEL) {
1847 LyXParagraph const * last = this;
1849 if( footnoteflag == NO_FOOTNOTE)
1850 last = LastPhysicalPar();
1851 else if (next->footnoteflag == NO_FOOTNOTE)
1852 return endlabeltype;
1857 if (!last || !last->next)
1858 return endlabeltype;
1860 int next_depth = last->next->GetDepth();
1861 if (par_depth > next_depth ||
1862 (par_depth == next_depth && layout != last->next->GetLayout() ))
1863 return endlabeltype;
1868 par = par->DepthHook(par_depth - 1);
1870 par_depth = par->GetDepth();
1872 return END_LABEL_NO_LABEL;
1876 LyXTextClass::size_type LyXParagraph::GetLayout() const
1879 return FirstPhysicalPar()->layout;
1886 char LyXParagraph::GetDepth() const
1889 return FirstPhysicalPar()->depth;
1896 char LyXParagraph::GetAlign() const
1899 return FirstPhysicalPar()->align;
1906 string const & LyXParagraph::GetLabelstring() const
1909 return FirstPhysicalPar()->labelstring;
1916 int LyXParagraph::GetFirstCounter(int i) const
1919 return FirstPhysicalPar()->counter_[i];
1926 // the next two functions are for the manual labels
1927 string LyXParagraph::GetLabelWidthString() const
1930 if (!FirstPhysicalPar()->labelwidthstring.empty())
1931 return FirstPhysicalPar()->labelwidthstring;
1933 if (!labelwidthstring.empty())
1934 return labelwidthstring;
1937 return _("Senseless with this layout!");
1941 void LyXParagraph::SetLabelWidthString(string const & s)
1944 LyXParagraph * par = FirstPhysicalPar();
1946 par->labelwidthstring = s;
1948 labelwidthstring = s;
1953 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1954 LyXTextClass::size_type new_layout)
1957 LyXParagraph * par = FirstPhysicalPar();
1959 LyXParagraph * par = this;
1961 LyXParagraph * ppar = 0;
1962 LyXParagraph * npar = 0;
1964 par->layout = new_layout;
1966 /* table stuff -- begin*/
1969 /* table stuff -- end*/
1971 if (par->pextra_type == PEXTRA_NONE) {
1972 if (par->Previous()) {
1974 ppar = par->Previous()->FirstPhysicalPar();
1976 ppar = par->Previous();
1980 && (ppar->depth > par->depth))
1982 ppar = ppar->Previous()->FirstPhysicalPar();
1984 ppar = ppar->Previous();
1989 npar = par->Next()->NextAfterFootnote();
1995 && (npar->depth > par->depth))
1997 npar = npar->Next()->NextAfterFootnote();
1999 npar = npar->Next();
2002 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2004 p1 = ppar->pextra_width,
2005 p2 = ppar->pextra_widthp;
2006 ppar->SetPExtraType(bparams, ppar->pextra_type,
2007 p1.c_str(), p2.c_str());
2009 if ((par->pextra_type == PEXTRA_NONE) &&
2010 npar && (npar->pextra_type != PEXTRA_NONE)) {
2012 p1 = npar->pextra_width,
2013 p2 = npar->pextra_widthp;
2014 npar->SetPExtraType(bparams, npar->pextra_type,
2015 p1.c_str(), p2.c_str());
2021 void LyXParagraph::SetLayout(BufferParams const & bparams,
2022 LyXTextClass::size_type new_layout)
2026 * par = FirstPhysicalPar(),
2033 par->layout = new_layout;
2034 par->labelwidthstring.erase();
2035 par->align = LYX_ALIGN_LAYOUT;
2036 par->added_space_top = VSpace(VSpace::NONE);
2037 par->added_space_bottom = VSpace(VSpace::NONE);
2038 par->spacing.set(Spacing::Default);
2041 /* table stuff -- begin*/
2044 /* table stuff -- end*/
2046 if (par->pextra_type == PEXTRA_NONE) {
2047 if (par->Previous()) {
2049 ppar = par->Previous()->FirstPhysicalPar();
2051 ppar = par->Previous();
2055 && (ppar->depth > par->depth))
2057 ppar = ppar->Previous()->FirstPhysicalPar();
2059 ppar = ppar->Previous();
2064 npar = par->Next()->NextAfterFootnote();
2070 && (npar->depth > par->depth))
2072 npar = npar->Next()->NextAfterFootnote();
2074 npar = npar->Next();
2077 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2079 p1 = ppar->pextra_width,
2080 p2 = ppar->pextra_widthp;
2081 ppar->SetPExtraType(bparams, ppar->pextra_type,
2082 p1.c_str(), p2.c_str());
2084 if ((par->pextra_type == PEXTRA_NONE) &&
2085 npar && (npar->pextra_type != PEXTRA_NONE)) {
2087 p1 = npar->pextra_width,
2088 p2 = npar->pextra_widthp;
2089 npar->SetPExtraType(bparams, npar->pextra_type,
2090 p1.c_str(), p2.c_str());
2096 // if the layout of a paragraph contains a manual label, the beginning of the
2097 // main body is the beginning of the second word. This is what the par-
2098 // function returns. If the layout does not contain a label, the main
2099 // body always starts with position 0. This differentiation is necessary,
2100 // because there cannot be a newline or a blank <= the beginning of the
2101 // main body in TeX.
2103 int LyXParagraph::BeginningOfMainBody() const
2106 if (FirstPhysicalPar() != this)
2109 // Unroll the first two cycles of the loop
2110 // and remember the previous character to
2111 // remove unnecessary GetChar() calls
2114 && GetChar(i) != LyXParagraph::META_NEWLINE
2117 char previous_char = 0, temp = 0;
2119 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2120 // Yes, this ^ is supposed to be "= " not "=="
2123 && previous_char != ' '
2124 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2126 previous_char = temp;
2132 if (i == 0 && i == size() &&
2133 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2134 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2135 ++i; /* the cursor should not jump
2136 * to the main body if there
2143 LyXParagraph * LyXParagraph::DepthHook(int deth)
2145 LyXParagraph * newpar = this;
2151 newpar = newpar->FirstPhysicalPar()->Previous();
2153 newpar = newpar->Previous();
2155 } while (newpar && newpar->GetDepth() > deth
2157 && newpar->footnoteflag == footnoteflag
2162 if (Previous() || GetDepth())
2163 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2168 return newpar->FirstPhysicalPar();
2175 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2177 LyXParagraph const * newpar = this;
2183 newpar = newpar->FirstPhysicalPar()->Previous();
2185 newpar = newpar->Previous();
2187 } while (newpar && newpar->GetDepth() > deth
2189 && newpar->footnoteflag == footnoteflag
2194 if (Previous() || GetDepth())
2195 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2200 return newpar->FirstPhysicalPar();
2207 int LyXParagraph::AutoDeleteInsets()
2210 InsetList::size_type index = 0;
2211 while (index < insetlist.size()) {
2212 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2213 Erase(insetlist[index].pos);
2214 // Erase() calls to insetlist.erase(&insetlist[index])
2215 // so index shouldn't be increased.
2224 LyXParagraph::inset_iterator
2225 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2227 InsetTable search_inset(pos, 0);
2228 InsetList::iterator it = lower_bound(insetlist.begin(),
2230 search_inset, matchIT());
2231 return inset_iterator(it);
2235 // returns -1 if inset not found
2236 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2239 for (InsetList::const_iterator cit = insetlist.begin();
2240 cit != insetlist.end(); ++cit) {
2241 if ((*cit).inset == inset) {
2246 // Think about footnotes.
2247 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2248 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2250 NextAfterFootnote()->GetPositionOfInset(inset);
2252 return text.size() + 1 + further;
2259 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2260 BufferParams const & bparams,
2261 ostream & os, TexRow & texrow,
2266 TexRow & foot_texrow,
2271 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2272 LyXLayout const & style =
2273 textclasslist.Style(bparams.textclass,
2276 bool further_blank_line = false;
2279 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2282 if (start_of_appendix) {
2283 os << "\\appendix\n";
2287 if (!spacing.isDefault()
2288 && (!Previous() || !Previous()->HasSameLayout(this))) {
2289 os << spacing.writeEnvirBegin() << "\n";
2293 if (tex_code_break_column && style.isCommand()){
2298 if (pagebreak_top) {
2300 further_blank_line = true;
2302 if (added_space_top.kind() != VSpace::NONE) {
2303 os << added_space_top.asLatexCommand(bparams);
2304 further_blank_line = true;
2308 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2309 << "\\vspace{-1\\parskip}";
2310 further_blank_line = true;
2313 if (further_blank_line){
2318 Language const * language = getParLanguage(bparams);
2319 Language const * doc_language = bparams.language_info;
2320 Language const * previous_language = previous
2321 ? previous->getParLanguage(bparams) : doc_language;
2322 if (language != doc_language && language != previous_language) {
2323 os << subst(lyxrc.language_command_begin, "$$lang",
2329 if (bparams.inputenc == "auto" &&
2330 language->encoding() != previous_language->encoding()) {
2331 os << "\\inputencoding{"
2332 << language->encoding()->LatexName()
2337 switch (style.latextype) {
2340 << style.latexname()
2341 << style.latexparam();
2343 case LATEX_ITEM_ENVIRONMENT:
2345 bibkey->Latex(buf, os, false, false);
2349 case LATEX_LIST_ENVIRONMENT:
2356 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2358 LyXParagraph * par = next;
2360 // Spit out footnotes
2361 if (lyxrc.rtl_support) {
2362 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2363 && next->footnoteflag != footnoteflag) {
2364 LyXParagraph * p = 0;
2365 bool is_rtl = (size() > 0)
2366 ? GetFontSettings(bparams,
2367 size()-1).isRightToLeft()
2368 : language->RightToLeft();
2369 if ( (p = NextAfterFootnote()) != 0 &&
2371 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2372 is_rtl = getParLanguage(bparams)->RightToLeft();
2373 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2374 && par->footnoteflag != footnoteflag) {
2375 par = par->TeXFootnote(buf, bparams,
2377 foot_texrow, foot_count,
2379 par->SimpleTeXOnePar(buf, bparams,
2380 os, texrow, moving_arg);
2381 is_rtl = (par->size() > 0)
2382 ? par->GetFontSettings(bparams,
2383 par->size()-1).isRightToLeft()
2384 : language->RightToLeft();
2386 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2387 (p = par->NextAfterFootnote()) != 0 &&
2389 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2390 is_rtl = language->RightToLeft();
2395 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2396 && par->footnoteflag != footnoteflag) {
2397 par = par->TeXFootnote(buf, bparams,
2399 foot, foot_texrow, foot_count,
2401 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2407 // Make sure that \\par is done with the font of the last
2408 // character if this has another size as the default.
2409 // This is necessary because LaTeX (and LyX on the screen)
2410 // calculates the space between the baselines according
2411 // to this font. (Matthias)
2412 LyXFont font = getFont(bparams, Last() - 1);
2414 if (style.resfont.size() != font.size()) {
2420 } else if (textclasslist.Style(bparams.textclass,
2421 GetLayout()).isCommand()) {
2422 if (style.resfont.size() != font.size()) {
2428 } else if (style.resfont.size() != font.size()){
2429 os << "{\\" << font.latexSize() << " \\par}";
2432 if (language != doc_language &&
2435 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2437 || par->getParLanguage(bparams) != language)) {
2439 << subst(lyxrc.language_command_end, "$$lang",
2440 doc_language->lang());
2443 switch (style.latextype) {
2444 case LATEX_ITEM_ENVIRONMENT:
2445 case LATEX_LIST_ENVIRONMENT:
2446 if (par && (depth < par->depth)) {
2451 case LATEX_ENVIRONMENT:
2452 // if its the last paragraph of the current environment
2453 // skip it otherwise fall through
2455 && (par->layout != layout
2456 || par->depth != depth
2457 || par->pextra_type != pextra_type))
2460 // we don't need it for the last paragraph!!!
2463 && !( footnoteflag != LyXParagraph::NO_FOOTNOTE
2464 && footnotekind != LyXParagraph::FOOTNOTE
2465 && footnotekind != LyXParagraph::MARGIN)
2473 // don't insert this if we would be adding it
2474 // before or after a table in a float. This
2475 // little trick is needed in order to allow
2476 // use of tables in \subfigures or \subtables.
2482 further_blank_line = false;
2484 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2485 further_blank_line = true;
2488 if (added_space_bottom.kind() != VSpace::NONE) {
2489 os << added_space_bottom.asLatexCommand(bparams);
2490 further_blank_line = true;
2493 if (pagebreak_bottom) {
2495 further_blank_line = true;
2498 if (further_blank_line){
2503 if (!spacing.isDefault()
2504 && (!par || !par->HasSameLayout(this))) {
2505 os << spacing.writeEnvirEnd() << "\n";
2509 // we don't need it for the last paragraph!!!
2512 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2513 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2520 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2525 // This one spits out the text of the paragraph
2526 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2527 BufferParams const & bparams,
2528 ostream & os, TexRow & texrow,
2531 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2535 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2538 bool return_value = false;
2540 LyXLayout const & style =
2541 textclasslist.Style(bparams.textclass,
2543 LyXFont basefont, last_font;
2545 // Maybe we have to create a optional argument.
2546 size_type main_body;
2547 if (style.labeltype != LABEL_MANUAL)
2550 main_body = BeginningOfMainBody();
2552 if (main_body > 0) {
2554 basefont = getFont(bparams, -2); // Get label font
2556 basefont = getFont(bparams, -1); // Get layout font
2567 if (style.isCommand()) {
2570 } else if (align != LYX_ALIGN_LAYOUT) {
2573 return_value = true;
2577 moving_arg |= style.needprotect;
2579 // Which font is currently active?
2580 LyXFont running_font(basefont);
2581 // Do we have an open font change?
2582 bool open_font = false;
2584 texrow.start(this, 0);
2586 for (size_type i = 0; i < size(); ++i) {
2588 // First char in paragraph or after label?
2594 if (main_body > 0) {
2596 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2599 basefont = getFont(bparams, -1); // Now use the layout font
2600 running_font = basefont;
2604 if (style.isCommand()) {
2607 } else if (align != LYX_ALIGN_LAYOUT) {
2610 return_value = true;
2614 os << "\\noindent ";
2618 case LYX_ALIGN_NONE:
2619 case LYX_ALIGN_BLOCK:
2620 case LYX_ALIGN_LAYOUT:
2621 case LYX_ALIGN_SPECIAL:
2623 case LYX_ALIGN_LEFT:
2624 if (getParLanguage(bparams)->lang() != "hebrew") {
2625 os << "\\raggedright ";
2628 os << "\\raggedleft ";
2632 case LYX_ALIGN_RIGHT:
2633 if (getParLanguage(bparams)->lang() != "hebrew") {
2634 os << "\\raggedleft ";
2637 os << "\\raggedright ";
2641 case LYX_ALIGN_CENTER:
2642 os << "\\centering ";
2648 value_type c = GetChar(i);
2650 // Fully instantiated font
2651 LyXFont font = getFont(bparams, i);
2653 LyXParagraph * p = 0;
2656 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2657 (p = PreviousBeforeFootnote()) != 0)
2658 last_font = p->getFont(bparams, p->size() - 1);
2661 last_font = running_font;
2663 // Spaces at end of font change are simulated to be
2664 // outside font change, i.e. we write "\textXX{text} "
2665 // rather than "\textXX{text }". (Asger)
2666 if (open_font && c == ' ' && i <= size() - 2
2667 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2668 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2669 font = getFont(bparams, i + 1);
2671 // We end font definition before blanks
2672 if (!font.equalExceptLatex(running_font) && open_font) {
2673 column += running_font.latexWriteEndChanges(os,
2675 (i == main_body-1) ? basefont : font);
2676 running_font = basefont;
2680 // Blanks are printed before start of fontswitch
2682 // Do not print the separation of the optional argument
2683 if (i != main_body - 1) {
2684 SimpleTeXBlanks(os, texrow, i,
2685 column, font, style);
2689 // Do we need to change font?
2690 if (!font.equalExceptLatex(running_font)
2691 && i != main_body-1) {
2692 column += font.latexWriteStartChanges(os, basefont,
2694 running_font = font;
2698 if (c == LyXParagraph::META_NEWLINE) {
2699 // newlines are handled differently here than
2700 // the default in SimpleTeXSpecialChars().
2701 if (!style.newline_allowed
2702 || font.latex() == LyXFont::ON) {
2706 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2709 basefont = getFont(bparams, -1);
2710 running_font = basefont;
2711 if (font.family() ==
2712 LyXFont::TYPEWRITER_FAMILY) {
2720 texrow.start(this, i + 1);
2723 SimpleTeXSpecialChars(buf, bparams,
2724 os, texrow, moving_arg,
2725 font, running_font, basefont,
2726 open_font, style, i, column, c);
2730 // If we have an open font definition, we have to close it
2732 LyXParagraph * p = 0;
2735 && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2736 && (p = NextAfterFootnote()) != 0
2741 running_font.latexWriteEndChanges(os, basefont,
2742 p->getFont(bparams, 0));
2744 running_font.latexWriteEndChanges(os, basefont, basefont);
2747 // Needed if there is an optional argument but no contents.
2748 if (main_body > 0 && main_body == size()) {
2750 return_value = false;
2753 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2754 return return_value;
2759 // This one spits out the text of a table paragraph
2760 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2761 BufferParams const & bparams,
2762 ostream & os, TexRow & texrow)
2764 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2766 bool return_value = false;
2768 LyXLayout const & style =
2769 textclasslist.Style(bparams.textclass, GetLayout());
2773 if (!IsDummy()) { // it is dummy if it is in a float!!!
2775 if (style.isCommand()) {
2778 } else if (align != LYX_ALIGN_LAYOUT) {
2781 return_value = true;
2784 os << "\\noindent ";
2788 case LYX_ALIGN_NONE:
2789 case LYX_ALIGN_BLOCK:
2790 case LYX_ALIGN_LAYOUT:
2791 case LYX_ALIGN_SPECIAL: break;
2792 case LYX_ALIGN_LEFT:
2793 os << "\\raggedright ";
2796 case LYX_ALIGN_RIGHT:
2797 os << "\\raggedleft ";
2800 case LYX_ALIGN_CENTER:
2801 os << "\\centering ";
2809 LyXFont basefont = getFont(bparams, -1); // Get layout font
2810 // Which font is currently active?
2811 LyXFont running_font = basefont;
2813 // Do we have an open font change?
2814 bool open_font = false;
2815 int current_cell_number = -1;
2816 int tmp = table->TexEndOfCell(os, current_cell_number);
2817 for (; tmp > 0 ; --tmp)
2820 texrow.start(this, 0);
2822 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2823 bool first_in_cell = true;
2825 for (size_type i = 0; i < size(); ++i) {
2826 value_type c = GetChar(i);
2827 if (table->IsContRow(current_cell_number + 1)) {
2828 if (c == LyXParagraph::META_NEWLINE)
2829 ++current_cell_number;
2834 if (first_in_cell && is_rtl) {
2837 first_in_cell = false;
2840 // Fully instantiated font
2841 LyXFont font = getFont(bparams, i);
2842 last_font = running_font;
2844 // Spaces at end of font change are simulated to be
2845 // outside font change.
2846 // i.e. we write "\textXX{text} " rather than
2847 // "\textXX{text }". (Asger)
2848 if (open_font && c == ' ' && i <= size() - 2
2849 && getFont(bparams, i + 1) != running_font
2850 && getFont(bparams, i + 1) != font) {
2851 font = getFont(bparams, i + 1);
2854 // We end font definition before blanks
2855 if (font != running_font && open_font) {
2856 column += running_font.latexWriteEndChanges(os,
2859 running_font = basefont;
2862 // Blanks are printed before start of fontswitch
2864 SimpleTeXBlanks(os, texrow, i, column, font, style);
2866 // Do we need to change font?
2867 if (font != running_font) {
2868 column += font.latexWriteStartChanges(os, basefont,
2870 running_font = font;
2873 // Do we need to turn on LaTeX mode?
2874 if (font.latex() != running_font.latex()) {
2875 if (font.latex() == LyXFont::ON
2876 && style.needprotect) {
2881 if (c == LyXParagraph::META_NEWLINE) {
2882 // special case for inside a table
2883 // different from default case in
2884 // SimpleTeXSpecialChars()
2886 column += running_font
2887 .latexWriteEndChanges(os, basefont,
2891 basefont = getFont(bparams, -1);
2892 running_font = basefont;
2893 ++current_cell_number;
2894 if (table->CellHasContRow(current_cell_number) >= 0) {
2895 TeXContTableRows(buf, bparams, os, i + 1,
2896 current_cell_number,
2899 if (is_rtl && !first_in_cell) {
2901 first_in_cell = true;
2904 // if this cell follow only ContRows till end don't
2905 // put the EndOfCell because it is put after the
2907 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2908 --current_cell_number;
2911 int tmp = table->TexEndOfCell(os,
2912 current_cell_number);
2915 } else if (tmp < 0) {
2921 texrow.start(this, i + 1);
2923 SimpleTeXSpecialChars(buf, bparams,
2925 font, running_font, basefont,
2926 open_font, style, i, column, c);
2930 // If we have an open font definition, we have to close it
2932 running_font.latexWriteEndChanges(os, basefont, basefont);
2934 ++current_cell_number;
2935 if (is_rtl && !first_in_cell)
2937 tmp = table->TexEndOfCell(os, current_cell_number);
2938 for (; tmp > 0; --tmp)
2940 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2941 return return_value;
2947 // This one spits out the text off ContRows in tables
2948 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2949 BufferParams const & bparams,
2951 LyXParagraph::size_type i,
2952 int current_cell_number,
2953 int & column, TexRow & texrow)
2955 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2959 bool return_value = false;
2960 LyXLayout const & style =
2961 textclasslist.Style(bparams.textclass,
2963 LyXFont basefont = getFont(bparams, -1); // Get layout font
2965 // Which font is currently active?
2966 LyXFont running_font = basefont;
2967 // Do we have an open font change?
2968 bool open_font = false;
2970 size_type lastpos = i;
2971 int cell = table->CellHasContRow(current_cell_number);
2972 ++current_cell_number;
2975 // first find the right position
2977 for (; (i < size()) && (current_cell_number < cell); ++i) {
2979 if (c == LyXParagraph::META_NEWLINE)
2980 ++current_cell_number;
2984 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2988 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2993 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2997 // Fully instantiated font
2998 LyXFont font = getFont(bparams, i);
2999 last_font = running_font;
3001 // Spaces at end of font change are simulated to
3002 // be outside font change. i.e. we write
3003 // "\textXX{text} " rather than "\textXX{text }".
3005 if (open_font && c == ' ' && i <= size() - 2
3006 && getFont(bparams, i + 1) != running_font
3007 && getFont(bparams, i + 1) != font) {
3008 font = getFont(bparams, i + 1);
3011 // We end font definition before blanks
3012 if (font != running_font && open_font) {
3013 column += running_font.latexWriteEndChanges(os, basefont, font);
3014 running_font = basefont;
3017 // Blanks are printed before start of fontswitch
3019 SimpleTeXBlanks(os, texrow, i,
3020 column, font, style);
3022 // Do we need to change font?
3023 if (font != running_font) {
3025 font.latexWriteStartChanges(os,
3028 running_font = font;
3031 // Do we need to turn on LaTeX mode?
3032 if (font.latex() != running_font.latex()) {
3033 if (font.latex() == LyXFont::ON
3034 && style.needprotect) {
3039 SimpleTeXSpecialChars(buf, bparams,
3040 os, texrow, false, font,
3041 running_font, basefont,
3042 open_font, style, i, column, c);
3044 // If we have an open font definition, we have to close it
3046 running_font.latexWriteEndChanges(os, basefont,
3050 basefont = getFont(bparams, -1);
3051 running_font = basefont;
3052 cell = table->CellHasContRow(current_cell_number);
3054 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
3055 return return_value;
3060 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
3062 bool retval = false;
3064 case LyXParagraph::META_HFILL:
3065 sgml_string.erase();
3067 case LyXParagraph::META_NEWLINE:
3071 sgml_string = "&";
3074 sgml_string = "<";
3077 sgml_string = ">";
3080 sgml_string = "$";
3083 sgml_string = "#";
3086 sgml_string = "%";
3089 sgml_string = "[";
3092 sgml_string = "]";
3095 sgml_string = "{";
3098 sgml_string = "}";
3101 sgml_string = "˜";
3104 sgml_string = """;
3107 sgml_string = "\";
3113 case '\0': // Ignore :-)
3114 sgml_string.erase();
3125 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
3126 ostream & os, string & extra,
3127 int & desc_on, int depth)
3129 BufferParams const & bparams = buffer->params;
3131 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
3133 LyXFont font1, font2;
3136 size_type main_body;
3137 bool emph_flag = false;
3139 LyXLayout const & style =
3140 textclasslist.Style(bparams.textclass,
3143 if (style.labeltype != LABEL_MANUAL)
3146 main_body = BeginningOfMainBody();
3148 // Gets paragraph main font.
3150 font1 = style.labelfont;
3154 int char_line_count = depth;
3155 os << newlineAndDepth(depth);
3157 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3158 os << "<INFORMALTABLE>"
3159 << newlineAndDepth(++depth);
3162 os << "<INFORMALTABLE>"
3163 << newlineAndDepth(++depth);
3165 int current_cell_number = -1;
3166 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3168 // Parsing main loop.
3169 for (size_type i = 0; i < size(); ++i) {
3171 if (table->IsContRow(current_cell_number+1)) {
3172 if (c == LyXParagraph::META_NEWLINE)
3173 ++current_cell_number;
3178 // Fully instantiated font
3179 font2 = getFont(bparams, i);
3181 // Handle <emphasis> tag.
3182 if (font1.emph() != font2.emph() && i) {
3183 if (font2.emph() == LyXFont::ON) {
3186 } else if (emph_flag) {
3187 os << "</emphasis>";
3191 if (c == LyXParagraph::META_NEWLINE) {
3192 // We have only to control for emphasis open here!
3194 os << "</emphasis>";
3197 font1 = font2 = getFont(bparams, -1);
3198 ++current_cell_number;
3199 if (table->CellHasContRow(current_cell_number) >= 0) {
3200 DocBookContTableRows(buffer,
3201 os, extra, desc_on, i + 1,
3202 current_cell_number,
3205 // if this cell follow only ContRows till end don't
3206 // put the EndOfCell because it is put after the
3208 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3209 --current_cell_number;
3212 tmp = table->DocBookEndOfCell(os,
3213 current_cell_number,
3218 } else if (c == LyXParagraph::META_INSET) {
3219 inset = GetInset(i);
3221 std::ostringstream ost;
3222 inset->DocBook(buffer, ost);
3223 string tmp_out = ost.str().c_str();
3226 inset->DocBook(buffer, ost);
3228 char * ctmp = ost.str();
3229 string tmp_out(ctmp);
3233 // This code needs some explanation:
3234 // Two insets are treated specially
3235 // label if it is the first element in a
3236 // command paragraph
3238 // graphics inside tables or figure floats
3240 // title (the equivalente in latex for this
3242 // and title should come first
3245 if(desc_on != 3 || i != 0) {
3246 if(tmp_out[0] == '@') {
3248 extra += frontStrip(tmp_out,
3251 os << frontStrip(tmp_out,
3256 } else if (font2.latex() == LyXFont::ON) {
3257 // "TeX"-Mode on == > SGML-Mode on.
3263 if (linuxDocConvertChar(c, sgml_string)
3264 && !style.free_spacing) {
3265 // in freespacing mode, spaces are
3266 // non-breaking characters
3271 << "</term><listitem><para>";
3283 // Needed if there is an optional argument but no contents.
3284 if (main_body > 0 && main_body == size()) {
3289 os << "</emphasis>";
3292 ++current_cell_number;
3293 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3294 // Resets description flag correctly.
3297 // <term> not closed...
3302 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3304 os << "</INFORMALTABLE>";
3306 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3313 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3314 ostream & os, string & extra,
3316 LyXParagraph::size_type i,
3317 int current_cell_number, int &column)
3322 BufferParams const & bparams = buffer->params;
3324 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3329 //string emph = "emphasis";
3330 bool emph_flag = false;
3331 int char_line_count = 0;
3333 LyXLayout const & style =
3334 textclasslist.Style(bparams.textclass,
3337 size_type main_body;
3338 if (style.labeltype != LABEL_MANUAL)
3341 main_body = BeginningOfMainBody();
3343 // Gets paragraph main font.
3346 font1 = style.labelfont;
3350 size_type lastpos = i;
3351 int cell = table->CellHasContRow(current_cell_number);
3352 ++current_cell_number;
3354 // first find the right position
3356 for (; i < size() && current_cell_number < cell; ++i) {
3358 if (c == LyXParagraph::META_NEWLINE)
3359 ++current_cell_number;
3363 // I don't know how to handle this so I comment it
3364 // for the moment (Jug)
3365 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3366 // file += " \\\\\n";
3369 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3374 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3378 // Fully instantiated font
3379 font2 = getFont(bparams, i);
3381 // Handle <emphasis> tag.
3382 if (font1.emph() != font2.emph() && i) {
3383 if (font2.emph() == LyXFont::ON) {
3386 } else if (emph_flag) {
3387 os << "</emphasis>";
3391 if (c == LyXParagraph::META_INSET) {
3392 inset = GetInset(i);
3394 std::ostringstream ost;
3395 inset->DocBook(buffer, ost);
3396 string tmp_out = ost.str().c_str();
3399 inset->DocBook(buffer, ost);
3401 char * ctmp = ost.str();
3402 string tmp_out(ctmp);
3406 // This code needs some explanation:
3407 // Two insets are treated specially
3408 // label if it is the first element in a
3409 // command paragraph
3411 // graphics inside tables or figure floats
3412 // can't go on title (the equivalente in
3413 // latex for this case is caption and title
3414 // should come first
3417 if(desc_on != 3 || i != 0) {
3418 if(tmp_out[0] == '@') {
3420 extra += frontStrip(tmp_out, '@');
3422 os << frontStrip(tmp_out, '@');
3426 } else if (font2.latex() == LyXFont::ON) {
3427 // "TeX"-Mode on == > SGML-Mode on.
3433 if (linuxDocConvertChar(c, sgml_string)
3434 && !style.free_spacing) {
3435 // in freespacing mode, spaces are
3436 // non-breaking characters
3441 << "</term><listitem><para>";
3451 // we have only to control for emphasis open here!
3453 os << "</emphasis>";
3456 font1 = font2 = getFont(bparams, -1);
3457 cell = table->CellHasContRow(current_cell_number);
3459 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3464 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3465 LyXParagraph::size_type const i,
3466 int & column, LyXFont const & font,
3467 LyXLayout const & style)
3469 if (column > tex_code_break_column
3471 && GetChar(i - 1) != ' '
3473 // In LaTeX mode, we don't want to
3474 // break lines since some commands
3476 && ! (font.latex() == LyXFont::ON)
3477 // same in FreeSpacing mode
3478 && !style.free_spacing
3479 // In typewriter mode, we want to avoid
3480 // ! . ? : at the end of a line
3481 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3482 && (GetChar(i-1) == '.'
3483 || GetChar(i-1) == '?'
3484 || GetChar(i-1) == ':'
3485 || GetChar(i-1) == '!'))) {
3486 if (tex_code_break_column == 0) {
3487 // in batchmode we need LaTeX to still
3488 // see it as a space not as an extra '\n'
3494 texrow.start(this, i + 1);
3496 } else if (font.latex() == LyXFont::OFF) {
3497 if (style.free_spacing) {
3506 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3507 BufferParams const & bparams,
3508 ostream & os, TexRow & texrow,
3511 LyXFont & running_font,
3514 LyXLayout const & style,
3515 LyXParagraph::size_type & i,
3517 LyXParagraph::value_type const c)
3519 // Two major modes: LaTeX or plain
3520 // Handle here those cases common to both modes
3521 // and then split to handle the two modes separately.
3523 case LyXParagraph::META_INSET: {
3524 Inset * inset = GetInset(i);
3527 int len = os.tellp();
3528 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3529 || inset->LyxCode() == Inset::MATH_CODE
3530 || inset->LyxCode() == Inset::URL_CODE)
3531 && running_font.isRightToLeft()) {
3536 int tmp = inset->Latex(buf, os, moving_arg,
3537 style.free_spacing);
3545 column += os.tellp() - len;
3554 case LyXParagraph::META_NEWLINE:
3556 column += running_font.latexWriteEndChanges(os,
3561 basefont = getFont(bparams, -1);
3562 running_font = basefont;
3565 case LyXParagraph::META_HFILL:
3571 // And now for the special cases within each mode
3572 // Are we in LaTeX mode?
3573 if (font.latex() == LyXFont::ON) {
3574 // at present we only have one option
3575 // but I'll leave it as a switch statement
3576 // so its simpler to extend. (ARRae)
3579 // make sure that we will not print
3580 // error generating chars to the tex
3581 // file. This test would not be needed
3582 // if it were done in the buffer
3590 // Plain mode (i.e. not LaTeX)
3593 os << "\\textbackslash{}";
3597 case '°': case '±': case '²': case '³':
3598 case '×': case '÷': case '¹': case 'ª':
3599 case 'º': case '¬': case 'µ':
3600 if (bparams.inputenc == "latin1" ||
3601 (bparams.inputenc == "auto" &&
3602 font.language()->encoding()->LatexName()
3604 os << "\\ensuremath{"
3613 case '|': case '<': case '>':
3614 // In T1 encoding, these characters exist
3615 if (lyxrc.fontenc == "T1") {
3617 //... but we should avoid ligatures
3618 if ((c == '>' || c == '<')
3620 && GetChar(i + 1) == c) {
3621 //os << "\\textcompwordmark{}";
3622 // Jean-Marc, have a look at
3623 // this. IÂ think this works
3631 // Typewriter font also has them
3632 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3636 // Otherwise, we use what LaTeX
3640 os << "\\textless{}";
3644 os << "\\textgreater{}";
3648 os << "\\textbar{}";
3654 case '-': // "--" in Typewriter mode -> "-{}-"
3656 && GetChar(i + 1) == '-'
3657 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3666 os << "\\char`\\\"{}";
3671 if (bparams.inputenc == "default") {
3680 case '%': case '#': case '{':
3687 os << "\\textasciitilde{}";
3692 os << "\\textasciicircum{}";
3696 case '*': case '[': case ']':
3697 // avoid being mistaken for optional arguments
3698 os << '{' << c << '}';
3703 // Blanks are printed before font switching.
3704 // Sure? I am not! (try nice-latex)
3705 // I am sure it's correct. LyX might be smarter
3706 // in the future, but for now, nothing wrong is
3711 /* idea for labels --- begin*/
3715 && font.family() != LyXFont::TYPEWRITER_FAMILY
3716 && GetChar(i + 1) == 'y'
3717 && GetChar(i + 2) == 'X') {
3725 && font.family() != LyXFont::TYPEWRITER_FAMILY
3726 && GetChar(i + 1) == 'e'
3727 && GetChar(i + 2) == 'X') {
3732 // Check for "LaTeX2e"
3735 && font.family() != LyXFont::TYPEWRITER_FAMILY
3736 && GetChar(i + 1) == 'a'
3737 && GetChar(i + 2) == 'T'
3738 && GetChar(i + 3) == 'e'
3739 && GetChar(i + 4) == 'X'
3740 && GetChar(i + 5) == '2'
3741 && GetChar(i + 6) == 'e') {
3746 // Check for "LaTeX"
3749 && font.family() != LyXFont::TYPEWRITER_FAMILY
3750 && GetChar(i + 1) == 'a'
3751 && GetChar(i + 2) == 'T'
3752 && GetChar(i + 3) == 'e'
3753 && GetChar(i + 4) == 'X') {
3757 /* idea for labels --- end*/
3758 } else if (c != '\0') {
3768 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3769 BufferParams const & bparams,
3770 ostream & os, TexRow & texrow
3773 TexRow & foot_texrow,
3778 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3779 LyXParagraph * par = this;
3782 (par->depth == depth)
3784 && (par->footnoteflag == footnoteflag)
3789 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3791 if (textclasslist.Style(bparams.textclass,
3792 par->layout).isEnvironment()
3793 || par->pextra_type != PEXTRA_NONE) {
3794 par = par->TeXEnvironment(buf, bparams,
3802 par = par->TeXOnePar(buf, bparams,
3812 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3818 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3819 BufferParams const & bparams,
3820 ostream & os, TexRow & texrow
3823 TexRow & foot_texrow,
3828 bool eindent_open = false;
3830 bool foot_this_level = false;
3832 // flags when footnotetext should be appended to file.
3833 static bool minipage_open = false;
3834 static int minipage_open_depth = 0;
3835 char par_sep = bparams.paragraph_separation;
3837 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3840 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3843 LyXLayout const & style =
3844 textclasslist.Style(bparams.textclass,
3847 if (pextra_type == PEXTRA_INDENT) {
3848 if (!pextra_width.empty()) {
3849 os << "\\begin{LyXParagraphIndent}{"
3850 << pextra_width << "}\n";
3852 //float ib = atof(pextra_widthp.c_str())/100;
3853 // string can't handle floats at present (971109)
3854 // so I'll do a conversion by hand knowing that
3855 // the limits are 0.0 to 1.0. ARRae.
3856 os << "\\begin{LyXParagraphIndent}{";
3857 switch (pextra_widthp.length()) {
3869 os << "\\columnwidth}\n";
3872 eindent_open = true;
3874 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3875 if (pextra_hfill && Previous() &&
3876 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3877 os << "\\hfill{}\n";
3880 if (par_sep == BufferParams::PARSEP_INDENT) {
3881 os << "{\\setlength\\parindent{0pt}\n";
3884 os << "\\begin{minipage}";
3885 switch(pextra_alignment) {
3886 case MINIPAGE_ALIGN_TOP:
3889 case MINIPAGE_ALIGN_MIDDLE:
3892 case MINIPAGE_ALIGN_BOTTOM:
3896 if (!pextra_width.empty()) {
3897 os << '{' << pextra_width << "}\n";
3899 //float ib = atof(par->pextra_width.c_str())/100;
3900 // string can't handle floats at present
3901 // so I'll do a conversion by hand knowing that
3902 // the limits are 0.0 to 1.0. ARRae.
3904 switch (pextra_widthp.length()) {
3916 os << "\\columnwidth}\n";
3919 if (par_sep == BufferParams::PARSEP_INDENT) {
3920 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3923 minipage_open = true;
3924 minipage_open_depth = depth;
3927 #ifdef WITH_WARNINGS
3928 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3929 //I disabled it because it breaks when lists span on several
3932 if (style.isEnvironment()){
3933 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3934 #ifdef FANCY_FOOTNOTE_CODE
3935 if (foot_count < 0) {
3936 // flag that footnote[mark][text] should be
3937 // used for any footnotes from now on
3939 foot_this_level = true;
3942 os << "\\begin{" << style.latexname() << "}{"
3943 << labelwidthstring << "}\n";
3944 } else if (style.labeltype == LABEL_BIBLIO) {
3946 os << "\\begin{" << style.latexname() << "}{"
3947 << bibitemWidest(current_view)
3949 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3950 #ifdef FANCY_FOOTNOTE_CODE
3951 if (foot_count < 0) {
3952 // flag that footnote[mark][text] should be
3953 // used for any footnotes from now on
3955 foot_this_level = true;
3958 os << "\\begin{" << style.latexname() << '}'
3959 << style.latexparam() << '\n';
3961 os << "\\begin{" << style.latexname() << '}'
3962 << style.latexparam() << '\n';
3965 LyXParagraph * par = this;
3967 par = par->TeXOnePar(buf, bparams,
3971 foot, foot_texrow, foot_count
3975 if (minipage_open && par && !style.isEnvironment() &&
3976 (par->pextra_type == PEXTRA_MINIPAGE) &&
3977 par->pextra_start_minipage) {
3978 os << "\\end{minipage}\n";
3980 if (par_sep == BufferParams::PARSEP_INDENT) {
3984 minipage_open = false;
3986 if (par && par->depth > depth) {
3987 if (textclasslist.Style(bparams.textclass,
3988 par->layout).isParagraph()
3993 // How to handle this? (Lgb)
3994 //&& !suffixIs(os, "\n\n")
3996 // There should be at least one '\n' already
3997 // but we need there to be two for Standard
3998 // paragraphs that are depth-increment'ed to be
3999 // output correctly. However, tables can
4000 // also be paragraphs so don't adjust them.
4003 // Will it ever harm to have one '\n' too
4004 // many? i.e. that we sometimes will have
4005 // three in a row. (Lgb)
4009 par = par->TeXDeeper(buf, bparams, os, texrow
4011 ,foot, foot_texrow, foot_count
4015 if (par && par->layout == layout && par->depth == depth &&
4016 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
4017 if (par->pextra_hfill && par->Previous() &&
4018 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
4019 os << "\\hfill{}\n";
4022 if (par_sep == BufferParams::PARSEP_INDENT) {
4023 os << "{\\setlength\\parindent{0pt}\n";
4026 os << "\\begin{minipage}";
4027 switch(par->pextra_alignment) {
4028 case MINIPAGE_ALIGN_TOP:
4031 case MINIPAGE_ALIGN_MIDDLE:
4034 case MINIPAGE_ALIGN_BOTTOM:
4038 if (!par->pextra_width.empty()) {
4039 os << '{' << par->pextra_width << "}\n";
4041 //float ib = atof(par->pextra_widthp.c_str())/100;
4042 // string can't handle floats at present
4043 // so I'll do a conversion by hand knowing that
4044 // the limits are 0.0 to 1.0. ARRae.
4046 switch (par->pextra_widthp.length()) {
4051 os << "0." << par->pextra_widthp;
4054 os << "0.0" << par->pextra_widthp;
4056 os << "\\columnwidth}\n";
4059 if (par_sep == BufferParams::PARSEP_INDENT) {
4060 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
4063 minipage_open = true;
4064 minipage_open_depth = par->depth;
4067 && par->layout == layout
4068 && par->depth == depth
4069 && par->pextra_type == pextra_type
4071 && par->footnoteflag == footnoteflag
4075 if (style.isEnvironment()) {
4076 os << "\\end{" << style.latexname() << '}';
4078 // maybe this should go after the minipage closes?
4079 if (foot_this_level) {
4080 if (foot_count >= 1) {
4081 if (foot_count > 1) {
4082 os << "\\addtocounter{footnote}{-"
4087 texrow += foot_texrow;
4089 foot_texrow.reset();
4095 if (minipage_open && (minipage_open_depth == depth) &&
4096 (!par || par->pextra_start_minipage ||
4097 par->pextra_type != PEXTRA_MINIPAGE)) {
4098 os << "\\end{minipage}\n";
4100 if (par_sep == BufferParams::PARSEP_INDENT) {
4104 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
4105 os << "\\medskip\n\n";
4109 minipage_open = false;
4112 os << "\\end{LyXParagraphIndent}\n";
4115 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
4116 && par->pextra_hfill)) {
4120 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
4121 return par; // ale970302
4126 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
4127 BufferParams const & bparams,
4128 ostream & os, TexRow & texrow,
4129 ostream & foot, TexRow & foot_texrow,
4133 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
4134 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
4135 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4136 "No footnote!" << endl;
4138 LyXParagraph * par = this;
4139 LyXLayout const & style =
4140 textclasslist.Style(bparams.textclass,
4141 previous->GetLayout());
4143 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
4144 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4145 "Float other than footnote in command"
4146 " with moving argument is illegal" << endl;
4149 if (footnotekind != LyXParagraph::FOOTNOTE
4150 && footnotekind != LyXParagraph::MARGIN
4153 // How to solve this?
4154 //&& !suffixIs(file, '\n')
4156 // we need to ensure that real floats like tables and figures
4157 // have their \begin{} on a new line otherwise we can get
4158 // incorrect results when using the endfloat.sty package
4159 // especially if two floats follow one another. ARRae 981022
4160 // NOTE: if the file is length 0 it must have just been
4161 // written out so we assume it ended with a '\n'
4163 // As far as I can see there is never any harm in writing
4164 // a '\n' too much. Please tell me if I am wrong. (Lgb)
4169 bool moving_arg = false;
4170 bool need_closing = false;
4171 bool is_rtl = isRightToLeftPar(bparams);
4173 if (is_rtl != parent_is_rtl) {
4178 need_closing = true;
4181 //BufferParams * params = ¤t_view->buffer()->params;
4182 bool footer_in_body = true;
4183 switch (footnotekind) {
4184 case LyXParagraph::FOOTNOTE:
4185 if (style.intitle) {
4186 os << "\\thanks{\n";
4187 footer_in_body = false;
4190 if (foot_count == -1) {
4191 // we're at depth 0 so we can use:
4192 os << "\\footnote{%\n";
4193 footer_in_body = false;
4195 os << "\\footnotemark{}%\n";
4197 // we only need this when there are
4198 // multiple footnotes
4199 os << "\\stepcounter{footnote}";
4201 os << "\\footnotetext{%\n";
4202 foot_texrow.start(this, 0);
4203 foot_texrow.newline();
4208 case LyXParagraph::MARGIN:
4209 os << "\\marginpar{\n";
4211 case LyXParagraph::FIG:
4212 if (pextra_type == PEXTRA_FLOATFLT
4213 && (!pextra_width.empty()
4214 || !pextra_widthp.empty())) {
4215 if (!pextra_width.empty())
4216 os << "\\begin{floatingfigure}{"
4217 << pextra_width << "}\n";
4219 os << "\\begin{floatingfigure}{"
4220 << atoi(pextra_widthp.c_str())/100.0
4221 << "\\textwidth}\n";
4223 os << "\\begin{figure}";
4224 if (!bparams.float_placement.empty()) {
4225 os << '[' << bparams.float_placement << "]\n";
4231 case LyXParagraph::TAB:
4232 os << "\\begin{table}";
4233 if (!bparams.float_placement.empty()) {
4234 os << '[' << bparams.float_placement << "]\n";
4239 case LyXParagraph::WIDE_FIG:
4240 os << "\\begin{figure*}";
4241 if (!bparams.float_placement.empty()) {
4242 os << '[' << bparams.float_placement << "]\n";
4247 case LyXParagraph::WIDE_TAB:
4248 os << "\\begin{table*}";
4249 if (!bparams.float_placement.empty()) {
4250 os << '[' << bparams.float_placement << "]\n";
4255 case LyXParagraph::ALGORITHM:
4256 os << "\\begin{algorithm}\n";
4261 if (footnotekind != LyXParagraph::FOOTNOTE
4262 || !footer_in_body) {
4263 // Process text for all floats except footnotes in body
4265 LyXLayout const & style =
4267 .Style(bparams.textclass, par->layout);
4269 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4271 if (style.isEnvironment()
4272 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4273 // Allows the use of minipages within float
4274 // environments. Shouldn't be circular because
4275 // we don't support footnotes inside
4276 // floats (yet). ARRae
4277 par = par->TeXEnvironment(buf, bparams, os,
4282 par = par->TeXOnePar(buf, bparams,
4283 os, texrow, moving_arg,
4288 if (par && !par->IsDummy() && par->depth > depth) {
4289 par = par->TeXDeeper(buf, bparams, os, texrow,
4293 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4295 // process footnotes > depth 0 or in environments separately
4296 // NOTE: Currently don't support footnotes within footnotes
4297 // even though that is possible using the \footnotemark
4299 std::ostringstream dummy;
4303 TexRow dummy_texrow;
4304 int dummy_count = 0;
4306 LyXLayout const & style =
4308 .Style(bparams.textclass, par->layout);
4310 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4312 if (style.isEnvironment()
4313 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4314 // Allows the use of minipages within float
4315 // environments. Shouldn't be circular because
4316 // we don't support footnotes inside
4317 // floats (yet). ARRae
4318 par = par->TeXEnvironment(buf, bparams,
4320 dummy, dummy_texrow,
4323 par = par->TeXOnePar(buf, bparams,
4326 dummy, dummy_texrow,
4330 if (par && !par->IsDummy() && par->depth > depth) {
4331 par = par->TeXDeeper(buf, bparams,
4333 dummy, dummy_texrow,
4337 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4339 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4340 "Footnote in a Footnote -- not supported"
4343 #ifndef HAVE_OSTREAM
4344 delete [] dummy.str();
4348 switch (footnotekind) {
4349 case LyXParagraph::FOOTNOTE:
4350 if (footer_in_body) {
4351 // This helps tell which of the multiple
4352 // footnotetexts an error was in.
4354 foot_texrow.newline();
4359 case LyXParagraph::MARGIN:
4362 case LyXParagraph::FIG:
4363 if (pextra_type == PEXTRA_FLOATFLT
4364 && (!pextra_width.empty()
4365 || !pextra_widthp.empty()))
4366 os << "\\end{floatingfigure}";
4368 os << "\\end{figure}";
4370 case LyXParagraph::TAB:
4371 os << "\\end{table}";
4373 case LyXParagraph::WIDE_FIG:
4374 os << "\\end{figure*}";
4376 case LyXParagraph::WIDE_TAB:
4377 os << "\\end{table*}";
4379 case LyXParagraph::ALGORITHM:
4380 os << "\\end{algorithm}";
4387 if (footnotekind != LyXParagraph::FOOTNOTE
4388 && footnotekind != LyXParagraph::MARGIN) {
4389 // we need to ensure that real floats like tables and figures
4390 // have their \end{} on a line of their own otherwise we can
4391 // get incorrect results when using the endfloat.sty package.
4396 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4401 bool LyXParagraph::IsDummy() const
4403 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4404 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4408 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4409 int type, char const * width,
4410 char const * widthp)
4413 pextra_width = width;
4414 pextra_widthp = widthp;
4416 if (textclasslist.Style(bparams.textclass,
4417 layout).isEnvironment()) {
4418 LyXParagraph * par = this;
4419 LyXParagraph * ppar = par;
4421 while (par && (par->layout == layout)
4422 && (par->depth == depth)) {
4424 par = par->Previous();
4427 par = par->FirstPhysicalPar();
4429 while (par && par->depth > depth) {
4430 par = par->Previous();
4433 par = par->FirstPhysicalPar();
4438 while (par && (par->layout == layout)
4439 && (par->depth == depth)) {
4440 par->pextra_type = type;
4441 par->pextra_width = width;
4442 par->pextra_widthp = widthp;
4444 par = par->NextAfterFootnote();
4448 if (par && (par->depth > depth))
4449 par->SetPExtraType(bparams,
4450 type, width, widthp);
4452 while (par && ((par->depth > depth) || par->IsDummy()))
4453 par = par->NextAfterFootnote();
4455 while (par && ((par->depth > depth)))
4463 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4465 if (pextra_type == PEXTRA_NONE)
4468 pextra_type = PEXTRA_NONE;
4469 pextra_width.erase();
4470 pextra_widthp.erase();
4472 if (textclasslist.Style(bparams.textclass,
4473 layout).isEnvironment()) {
4474 LyXParagraph * par = this;
4475 LyXParagraph * ppar = par;
4477 while (par && (par->layout == layout)
4478 && (par->depth == depth)) {
4480 par = par->Previous();
4483 par = par->FirstPhysicalPar();
4485 while (par && par->depth > depth) {
4486 par = par->Previous();
4489 par = par->FirstPhysicalPar();
4494 while (par && (par->layout == layout)
4495 && (par->depth == depth)) {
4496 par->pextra_type = PEXTRA_NONE;
4497 par->pextra_width.erase();
4498 par->pextra_widthp.erase();
4500 par = par->NextAfterFootnote();
4504 if (par && (par->depth > depth))
4505 par->UnsetPExtraType(bparams);
4507 while (par && ((par->depth > depth) || par->IsDummy()))
4508 par = par->NextAfterFootnote();
4510 while (par && ((par->depth > depth)))
4518 bool LyXParagraph::IsHfill(size_type pos) const
4520 return IsHfillChar(GetChar(pos));
4524 bool LyXParagraph::IsInset(size_type pos) const
4526 return IsInsetChar(GetChar(pos));
4531 bool LyXParagraph::IsFloat(size_type pos) const
4533 return IsFloatChar(GetChar(pos));
4538 bool LyXParagraph::IsNewline(size_type pos) const
4540 return pos >= 0 && IsNewlineChar(GetChar(pos));
4544 bool LyXParagraph::IsSeparator(size_type pos) const
4546 return IsSeparatorChar(GetChar(pos));
4550 bool LyXParagraph::IsLineSeparator(size_type pos) const
4552 return IsLineSeparatorChar(GetChar(pos));
4556 bool LyXParagraph::IsKomma(size_type pos) const
4558 return IsKommaChar(GetChar(pos));
4562 /// Used by the spellchecker
4563 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4565 value_type c = GetChar(pos);
4566 if (IsLetterChar(c))
4568 // '\0' is not a letter, allthough every string contains "" (below)
4571 // We want to pass the ' and escape chars to ispell
4572 string extra = lyxrc.isp_esc_chars + '\'';
4573 char ch[2] = { c, 0 };
4574 return contains(extra, ch);
4578 bool LyXParagraph::IsWord(size_type pos ) const
4580 return IsWordChar(GetChar(pos)) ;
4585 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4589 return FirstPhysicalPar()->getParLanguage(bparams);
4596 return GetFirstFontSettings().language();
4599 for (size_type pos = 0; pos < size(); ++pos)
4601 return GetFontSettings(bparams, pos).language();
4602 return GetFirstFontSettings().language();
4606 return previous->getParLanguage(bparams);
4608 return bparams.language_info;
4612 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4614 return lyxrc.rtl_support
4618 && getParLanguage(bparams)->RightToLeft();
4622 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4623 Language const * from, Language const * to)
4625 for(size_type i = 0; i < size(); ++i) {
4626 LyXFont font = GetFontSettings(bparams, i);
4627 if (font.language() == from) {
4628 font.setLanguage(to);
4635 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4637 Language const * doc_language = bparams.language_info;
4638 for (FontList::const_iterator cit = fontlist.begin();
4639 cit != fontlist.end(); ++cit)
4640 if ((*cit).font.language() != doc_language)
4646 // Convert the paragraph to a string.
4647 // Used for building the table of contents
4648 string LyXParagraph::String(Buffer const * buffer, bool label)
4650 BufferParams const & bparams = buffer->params;
4653 if (label && !IsDummy() && !labelstring.empty())
4655 if (label && !labelstring.empty())
4657 s += labelstring + ' ';
4658 string::size_type len = s.size();
4660 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4661 value_type c = GetChar(i);
4664 else if (c == META_INSET &&
4665 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4667 std::ostringstream ost;
4668 GetInset(i)->Ascii(buffer, ost);
4671 GetInset(i)->Ascii(buffer, ost);
4674 s += subst(ost.str(),'\n',' ');
4679 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4680 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4681 s += NextAfterFootnote()->String(buffer, false);
4685 if (isRightToLeftPar(bparams))
4686 reverse(s.begin() + len,s.end());
4694 string LyXParagraph::String(Buffer const * buffer,
4695 LyXParagraph::size_type beg,
4696 LyXParagraph::size_type end)
4703 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4705 if (cell >= table->NumberOfCellsInRow(actcell))
4714 if (beg == 0 && !IsDummy() && !labelstring.empty())
4716 if (beg == 0 && !labelstring.empty())
4718 s += labelstring + ' ';
4720 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4721 value_type c = GetChar(i);
4724 else if (c == META_INSET) {
4726 std::ostringstream ost;
4727 GetInset(i)->Ascii(buffer, ost);
4730 GetInset(i)->Ascii(buffer, ost);
4736 else if (table && IsNewlineChar(c)) {
4737 if (cell >= table->NumberOfCellsInRow(actcell)) {
4753 void LyXParagraph::SetInsetOwner(Inset *i)
4756 for (InsetList::const_iterator cit = insetlist.begin();
4757 cit != insetlist.end(); ++cit) {
4759 (*cit).inset->setOwner(i);
4764 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4767 for (InsetList::const_iterator cit = insetlist.begin();
4768 cit != insetlist.end(); ++cit) {
4770 if ((*cit).inset->IsTextInset()) {
4771 static_cast<UpdatableInset *>
4772 ((*cit).inset)->deleteLyXText(bv);
4779 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4782 for (InsetList::const_iterator cit = insetlist.begin();
4783 cit != insetlist.end(); ++cit) {
4785 if ((*cit).inset->IsTextInset()) {
4786 static_cast<UpdatableInset *>
4787 ((*cit).inset)->resizeLyXText(bv);