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"
41 #include "ParameterStruct.h"
47 using std::lower_bound;
48 using std::upper_bound;
51 int tex_code_break_column = 72; // needs non-zero initialization. set later.
52 // this is a bad idea, but how can LyXParagraph find its buffer to get
53 // parameters? (JMarc)
55 extern string bibitemWidest(Buffer const *);
57 // this is a minibuffer
58 static char minibuffer_char;
59 static LyXFont minibuffer_font;
60 static Inset * minibuffer_inset;
63 extern BufferView * current_view;
65 // Initialization of the counter for the paragraph id's,
66 // declared in lyxparagraph.h
67 unsigned int LyXParagraph::paragraph_id = 0;
69 // Initialize static member.
70 ShareContainer<LyXFont> LyXParagraph::FontTable::container;
73 LyXParagraph::LyXParagraph()
75 text.reserve(500); // is this number too big?
76 for (int i = 0; i < 10; ++i) setCounter(i , 0);
82 footnoteflag = LyXParagraph::NO_FOOTNOTE;
83 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
88 bibkey = 0; // ale970302
93 // This konstruktor inserts the new paragraph in a list.
94 LyXParagraph::LyXParagraph(LyXParagraph * par)
99 for (int i = 0; i < 10; ++i) setCounter(i, 0);
102 // double linked list begin
105 next_->previous_ = this;
107 previous_->next_ = this;
110 footnoteflag = LyXParagraph::NO_FOOTNOTE;
111 footnotekind = LyXParagraph::FOOTNOTE;
114 id_ = paragraph_id++;
116 bibkey = 0; // ale970302
122 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
123 BufferParams const & bparams,
124 char footflag, char dth) const
128 footnoteflag != LyXParagraph::NO_FOOTNOTE ||
130 || previous_->footnoteflag == LyXParagraph::NO_FOOTNOTE
135 // The beginning or the end of a footnote environment?
136 if (footflag != footnoteflag) {
137 footflag = footnoteflag;
139 os << "\n\\begin_float "
140 << string_footnotekinds[footnotekind]
143 os << "\n\\end_float ";
147 // The beginning or end of a deeper (i.e. nested) area?
148 if (dth != params.depth()) {
149 if (params.depth() > dth) {
150 while (params.depth() > dth) {
151 os << "\n\\begin_deeper ";
155 while (params.depth() < dth) {
156 os << "\n\\end_deeper ";
162 // First write the layout
164 << textclasslist.NameOfLayout(bparams.textclass, layout)
167 // Maybe some vertical spaces.
168 if (params.spaceTop().kind() != VSpace::NONE)
169 os << "\\added_space_top "
170 << params.spaceTop().asLyXCommand() << " ";
171 if (params.spaceBottom().kind() != VSpace::NONE)
172 os << "\\added_space_bottom "
173 << params.spaceBottom().asLyXCommand() << " ";
175 // Maybe the paragraph has special spacing
176 params.spacing().writeFile(os, true);
178 // The labelwidth string used in lists.
179 if (!params.labelWidthString().empty())
180 os << "\\labelwidthstring "
181 << params.labelWidthString() << '\n';
183 // Lines above or below?
184 if (params.lineTop())
186 if (params.lineBottom())
187 os << "\\line_bottom ";
189 // Pagebreaks above or below?
190 if (params.pagebreakTop())
191 os << "\\pagebreak_top ";
192 if (params.pagebreakBottom())
193 os << "\\pagebreak_bottom ";
195 // Start of appendix?
196 if (params.startOfAppendix())
197 os << "\\start_of_appendix ";
200 if (params.noindent())
204 if (params.align() != LYX_ALIGN_LAYOUT) {
206 switch (params.align()) {
207 case LYX_ALIGN_LEFT: h = 1; break;
208 case LYX_ALIGN_RIGHT: h = 2; break;
209 case LYX_ALIGN_CENTER: h = 3; break;
210 default: h = 0; break;
212 os << "\\align " << string_align[h] << " ";
214 if (params.pextraType() != PEXTRA_NONE) {
215 os << "\\pextra_type " << params.pextraType();
216 if (params.pextraType() == PEXTRA_MINIPAGE) {
217 os << " \\pextra_alignment "
218 << params.pextraAlignment();
219 if (params.pextraHfill())
220 os << " \\pextra_hfill "
221 << params.pextraHfill();
222 if (params.pextraStartMinipage())
223 os << " \\pextra_start_minipage "
224 << params.pextraStartMinipage();
226 if (!params.pextraWidth().empty()) {
227 os << " \\pextra_width "
228 << VSpace(params.pextraWidth()).asLyXCommand();
229 } else if (!params.pextraWidthp().empty()) {
230 os << " \\pextra_widthp "
231 << params.pextraWidthp();
237 // Dummy layout. This means that a footnote ended.
238 os << "\n\\end_float ";
239 footflag = LyXParagraph::NO_FOOTNOTE;
245 bibkey->Write(buf, os);
247 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
250 for (size_type i = 0; i < size(); ++i) {
256 // Write font changes
257 LyXFont font2 = GetFontSettings(bparams, i);
258 if (font2 != font1) {
259 font2.lyxWriteChanges(font1, os);
264 value_type const c = GetChar(i);
268 Inset const * inset = GetInset(i);
270 if (inset->DirectWrite()) {
271 // international char, let it write
272 // code directly so it's shorter in
274 inset->Write(buf, os);
276 os << "\n\\begin_inset ";
277 inset->Write(buf, os);
278 os << "\n\\end_inset \n\n";
284 os << "\n\\newline \n";
288 os << "\n\\hfill \n";
292 os << "\n\\backslash \n";
296 if (i + 1 < size() && GetChar(i + 1) == ' ') {
303 if ((column > 70 && c == ' ')
308 // this check is to amend a bug. LyX sometimes
309 // inserts '\0' this could cause problems.
313 lyxerr << "ERROR (LyXParagraph::writeFile):"
314 " NULL char in structure." << endl;
320 // now write the next paragraph
322 next_->writeFile(buf, os, bparams, footflag, dth);
326 void LyXParagraph::validate(LaTeXFeatures & features) const
328 BufferParams const & bparams = features.bufferParams();
331 // this will be useful later
332 LyXLayout const & layout =
333 textclasslist.Style(bparams.textclass,
338 if (params.lineTop() || params.lineBottom())
339 features.lyxline = true;
340 if (!params.spacing().isDefault())
341 features.setspace = true;
344 features.layout[GetLayout()] = true;
347 Language const * doc_language = bparams.language;
349 for (FontList::const_iterator cit = fontlist.begin();
350 cit != fontlist.end(); ++cit) {
351 if ((*cit).font().noun() == LyXFont::ON) {
352 lyxerr[Debug::LATEX] << "font.noun: "
353 << (*cit).font().noun()
355 features.noun = true;
356 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
357 << (*cit).font().stateText(0)
360 switch ((*cit).font().color()) {
362 case LColor::inherit:
366 features.color = true;
367 lyxerr[Debug::LATEX] << "Color enabled. Font: "
368 << (*cit).font().stateText(0)
372 Language const * language = (*cit).font().language();
373 if (language->babel() != doc_language->babel()) {
374 features.UsedLanguages.insert(language);
375 lyxerr[Debug::LATEX] << "Found language "
376 << language->babel() << endl;
381 for (InsetList::const_iterator cit = insetlist.begin();
382 cit != insetlist.end(); ++cit) {
384 (*cit).inset->Validate(features);
387 if (params.pextraType() == PEXTRA_INDENT)
388 features.LyXParagraphIndent = true;
389 if (params.pextraType() == PEXTRA_FLOATFLT)
390 features.floatflt = true;
392 if (layout.needprotect
393 && next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
394 features.NeedLyXFootnoteCode = true;
396 if (bparams.paragraph_separation == BufferParams::PARSEP_INDENT
397 && params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE)
398 features.NeedLyXMinipageIndent = true;
400 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
401 features.algorithm = true;
406 // First few functions needed for cut and paste and paragraph breaking.
407 void LyXParagraph::CopyIntoMinibuffer(Buffer const & buffer,
408 LyXParagraph::size_type pos) const
410 BufferParams bparams = buffer.params;
412 minibuffer_char = GetChar(pos);
413 minibuffer_font = GetFontSettings(bparams, pos);
414 minibuffer_inset = 0;
415 if (minibuffer_char == LyXParagraph::META_INSET) {
417 minibuffer_inset = GetInset(pos)->Clone(buffer);
419 minibuffer_inset = 0;
420 minibuffer_char = ' ';
421 // This reflects what GetInset() does (ARRae)
427 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
428 LyXParagraph::size_type pos)
430 minibuffer_char = GetChar(pos);
431 minibuffer_font = GetFontSettings(bparams, pos);
432 minibuffer_inset = 0;
433 if (minibuffer_char == LyXParagraph::META_INSET) {
435 minibuffer_inset = GetInset(pos);
436 // This is a little hack since I want exactly
437 // the inset, not just a clone. Otherwise
438 // the inset would be deleted when calling Erase(pos)
440 InsetTable search_elem(pos, 0);
441 InsetList::iterator it =
442 lower_bound(insetlist.begin(),
444 search_elem, matchIT());
445 if (it != insetlist.end() && (*it).pos == pos)
448 minibuffer_inset = 0;
449 minibuffer_char = ' ';
450 // This reflects what GetInset() does (ARRae)
455 // Erase(pos); now the caller is responsible for that.
459 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
461 if ((minibuffer_char == LyXParagraph::META_INSET) &&
462 !InsertInsetAllowed(minibuffer_inset))
464 if (minibuffer_char == LyXParagraph::META_INSET)
465 InsertInset(pos, minibuffer_inset, minibuffer_font);
467 InsertChar(pos, minibuffer_char, minibuffer_font);
475 void LyXParagraph::Clear()
484 // the destructor removes the new paragraph from the list
485 LyXParagraph::~LyXParagraph()
488 previous_->next_ = next_;
490 next_->previous_ = previous_;
492 for (InsetList::iterator it = insetlist.begin();
493 it != insetlist.end(); ++it) {
500 //lyxerr << "LyXParagraph::paragraph_id = "
501 // << LyXParagraph::paragraph_id << endl;
505 void LyXParagraph::Erase(LyXParagraph::size_type pos)
508 // > because last is the next unused position, and you can
509 // use it if you want
511 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
512 NextAfterFootnote()->Erase(pos - text.size() - 1);
514 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
515 "position does not exist." << endl;
519 Assert(pos < size());
522 if (pos < size()) { // last is free for insertation, but should be empty
524 // if it is an inset, delete the inset entry
525 if (text[pos] == LyXParagraph::META_INSET) {
527 InsetTable search_inset(pos, 0);
528 InsetList::iterator it =
529 lower_bound(insetlist.begin(),
531 search_inset, matchIT());
532 if (it != insetlist.end() && (*it).pos == pos) {
538 text.erase(text.begin() + pos);
540 // Erase entries in the tables.
541 FontTable search_font(pos, LyXFont());
543 FontList::iterator it =
544 lower_bound(fontlist.begin(),
546 search_font, matchFT());
547 if (it != fontlist.end() && (*it).pos() == pos &&
549 (it != fontlist.begin() && (*(it - 1)).pos() == pos - 1))) {
550 // If it is a multi-character font
551 // entry, we just make it smaller
552 // (see update below), otherwise we
554 unsigned int const i = it - fontlist.begin();
555 fontlist.erase(fontlist.begin() + i);
556 it = fontlist.begin() + i;
557 if (i > 0 && i < fontlist.size() &&
558 fontlist[i - 1].font() == fontlist[i].font()) {
559 fontlist.erase(fontlist.begin() + i - 1);
560 it = fontlist.begin() + i - 1;
564 // Update all other entries.
565 FontList::iterator fend = fontlist.end();
566 for (; it != fend; ++it)
567 (*it).pos((*it).pos() - 1);
569 // Update the inset table.
570 InsetTable search_inset(pos, 0);
571 InsetList::iterator lend = insetlist.end();
572 for (InsetList::iterator it =
573 upper_bound(insetlist.begin(),
575 search_inset, matchIT());
580 lyxerr << "ERROR (LyXParagraph::Erase): "
581 "can't erase non-existant char." << endl;
587 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
588 LyXParagraph::value_type c)
590 LyXFont const f(LyXFont::ALL_INHERIT);
591 InsertChar(pos, c, f);
595 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
596 LyXParagraph::value_type c,
597 LyXFont const & font)
600 // > because last is the next unused position, and you can
601 // use it if you want
604 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
605 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
608 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
609 "position does not exist." << endl;
613 Assert(pos <= size());
615 text.insert(text.begin() + pos, c);
617 // Update the font table.
618 FontTable search_font(pos, LyXFont());
619 for (FontList::iterator it = lower_bound(fontlist.begin(),
621 search_font, matchFT());
622 it != fontlist.end(); ++it)
623 (*it).pos((*it).pos() + 1);
625 // Update the inset table.
626 InsetTable search_inset(pos, 0);
627 for (InsetList::iterator it = lower_bound(insetlist.begin(),
629 search_inset, matchIT());
630 it != insetlist.end(); ++it)
637 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
640 LyXFont const f(LyXFont::ALL_INHERIT);
641 InsertInset(pos, inset, f);
645 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
646 Inset * inset, LyXFont const & font)
651 // > because last is the next unused position, and you can
652 // use it if you want
655 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
657 ->InsertInset(pos - text.size() - 1,
660 lyxerr << "ERROR (LyXParagraph::InsertInset): "
661 "position does not exist: " << pos << endl;
665 Assert(pos <= size());
668 InsertChar(pos, META_INSET, font);
669 Assert(text[pos] == META_INSET);
671 // Add a new entry in the inset table.
672 InsetTable search_inset(pos, 0);
673 InsetList::iterator it = lower_bound(insetlist.begin(),
675 search_inset, matchIT());
676 if (it != insetlist.end() && (*it).pos == pos)
677 lyxerr << "ERROR (LyXParagraph::InsertInset): "
678 "there is an inset in position: " << pos << endl;
680 insetlist.insert(it, InsetTable(pos, inset));
682 inset->setOwner(inset_owner);
686 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
688 //lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
691 return inset_owner->InsertInsetAllowed(inset);
696 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
701 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
702 return NextAfterFootnote()
703 ->GetInset(pos - text.size() - 1);
705 lyxerr << "ERROR (LyXParagraph::GetInset): "
706 "position does not exist: "
712 Assert(pos < size());
715 InsetTable search_inset(pos, 0);
716 InsetList::iterator it = lower_bound(insetlist.begin(),
718 search_inset, matchIT());
719 if (it != insetlist.end() && (*it).pos == pos)
722 lyxerr << "ERROR (LyXParagraph::GetInset): "
723 "Inset does not exist: " << pos << endl;
726 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
727 // Did this commenting out introduce a bug? So far I have not
728 // see any, please enlighten me. (Lgb)
729 // My guess is that since the inset does not exist, we might
730 // as well replace it with a space to prevent craches. (Asger)
735 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
740 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
741 return NextAfterFootnote()
742 ->GetInset(pos - text.size() - 1);
744 lyxerr << "ERROR (LyXParagraph::GetInset): "
745 "position does not exist: "
751 Assert(pos < size());
754 InsetTable search_inset(pos, 0);
755 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
757 search_inset, matchIT());
758 if (cit != insetlist.end() && (*cit).pos == pos)
761 lyxerr << "ERROR (LyXParagraph::GetInset): "
762 "Inset does not exist: " << pos << endl;
764 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
765 // Did this commenting out introduce a bug? So far I have not
766 // see any, please enlighten me. (Lgb)
767 // My guess is that since the inset does not exist, we might
768 // as well replace it with a space to prevent craches. (Asger)
773 // Gets uninstantiated font setting at position.
774 // Optimized after profiling. (Asger)
775 LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
776 LyXParagraph::size_type pos) const
779 Assert(pos <= size());
784 FontTable search_font(pos, LyXFont());
785 FontList::const_iterator cit = lower_bound(fontlist.begin(),
787 search_font, matchFT());
788 if (cit != fontlist.end())
789 return (*cit).font();
794 // > because last is the next unused position, and you can
795 // use it if you want
796 else if (pos > size()) {
798 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
799 return NextAfterFootnote()
800 ->GetFontSettings(bparams,
801 pos - text.size() - 1);
803 // Why is it an error to ask for the font of a
804 // position that does not exist? Would it be
805 // enough for this to be enabled on debug?
806 // We want strict error checking, but it's ok to only
807 // have it when debugging. (Asger)
808 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
809 "position does not exist. "
810 << pos << " (" << static_cast<int>(pos)
812 } else if (pos > 0) {
813 return GetFontSettings(bparams, pos - 1);
816 if (pos == size() && size())
817 return GetFontSettings(bparams, pos - 1);
821 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
823 //return LyXFont(LyXFont::ALL_INHERIT);
827 // Gets uninstantiated font setting at position 0
828 LyXFont const LyXParagraph::GetFirstFontSettings() const
831 if (!fontlist.empty())
832 return fontlist[0].font();
836 else if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
837 return NextAfterFootnote()->GetFirstFontSettings();
839 return LyXFont(LyXFont::ALL_INHERIT);
843 // Gets the fully instantiated font at a given position in a paragraph
844 // This is basically the same function as LyXText::GetFont() in text2.C.
845 // The difference is that this one is used for generating the LaTeX file,
846 // and thus cosmetic "improvements" are disallowed: This has to deliver
847 // the true picture of the buffer. (Asger)
848 // If position is -1, we get the layout font of the paragraph.
849 // If position is -2, we get the font of the manual label of the paragraph.
850 LyXFont const LyXParagraph::getFont(BufferParams const & bparams,
851 LyXParagraph::size_type pos) const
854 LyXLayout const & layout =
855 textclasslist.Style(bparams.textclass,
857 LyXParagraph::size_type main_body = 0;
858 if (layout.labeltype == LABEL_MANUAL)
859 main_body = BeginningOfMainBody();
864 layoutfont = layout.labelfont;
866 layoutfont = layout.font;
867 tmpfont = GetFontSettings(bparams, pos);
868 tmpfont.realize(layoutfont);
870 // process layoutfont for pos == -1 and labelfont for pos < -1
872 tmpfont = layout.font;
874 tmpfont = layout.labelfont;
875 tmpfont.setLanguage(getParLanguage(bparams));
878 // check for environment font information
879 char par_depth = GetDepth();
880 LyXParagraph const * par = this;
881 while (par && par_depth && !tmpfont.resolved()) {
882 par = par->DepthHook(par_depth - 1);
884 tmpfont.realize(textclasslist.
885 Style(bparams.textclass,
886 par->GetLayout()).font);
887 par_depth = par->GetDepth();
891 tmpfont.realize(textclasslist
892 .TextClass(bparams.textclass)
898 /// Returns the height of the highest font in range
900 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
901 LyXParagraph::size_type endpos) const
903 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
904 if (fontlist.empty())
907 FontTable end_search(endpos, LyXFont());
908 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
910 end_search, matchFT());
911 if (end_it != fontlist.end())
914 FontTable start_search(startpos, LyXFont());
915 for (FontList::const_iterator cit =
916 lower_bound(fontlist.begin(),
918 start_search, matchFT());
919 cit != end_it; ++cit) {
920 LyXFont::FONT_SIZE size = (*cit).font().size();
921 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
928 LyXParagraph::value_type
929 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
934 Assert(pos <= size());
935 if (!size() || pos == size()) return '\0';
946 // > because last is the next unused position, and you can
947 // use it if you want
948 else if (pos > size()) {
949 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
950 return NextAfterFootnote()
951 ->GetChar(pos - text.size() - 1);
954 lyxerr << "ERROR (LyXParagraph::GetChar const): "
955 "position does not exist."
956 << pos << " (" << static_cast<int>(pos)
962 // We should have a footnote environment.
963 if (!next_ || next_->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
964 // Notice that LyX does request the
965 // last char from time to time. (Asger)
966 //lyxerr << "ERROR (LyXParagraph::GetChar): "
967 // "expected footnote." << endl;
970 switch (next_->footnotekind) {
971 case LyXParagraph::FOOTNOTE:
972 return LyXParagraph::META_FOOTNOTE;
973 case LyXParagraph::MARGIN:
974 return LyXParagraph::META_MARGIN;
975 case LyXParagraph::FIG:
976 case LyXParagraph::WIDE_FIG:
977 return LyXParagraph::META_FIG;
978 case LyXParagraph::TAB:
979 case LyXParagraph::WIDE_TAB:
980 return LyXParagraph::META_TAB;
981 case LyXParagraph::ALGORITHM:
982 return LyXParagraph::META_ALGORITHM;
984 return '\0'; // to shut up gcc
990 LyXParagraph::value_type
991 LyXParagraph::GetUChar(BufferParams const & bparams,
992 LyXParagraph::size_type pos) const
994 value_type c = GetChar(pos);
995 if (!lyxrc.rtl_support)
1025 if (uc != c && GetFontSettings(bparams, pos).isRightToLeft())
1031 // return an string of the current word, and the end of the word in lastpos.
1032 string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1034 Assert(lastpos >= 0);
1036 // the current word is defined as starting at the first character
1037 // from the immediate left of lastpospos which meets the definition
1038 // of IsLetter(), continuing to the last character to the right
1039 // of this meeting IsLetter.
1045 // move back until we have a letter
1047 //there's no real reason to have firstpos & lastpos as
1048 //separate variables as this is written, but maybe someon
1049 // will want to return firstpos in the future.
1051 //since someone might have typed a punctuation first
1052 int firstpos = lastpos;
1054 while ((firstpos >= 0) && !IsLetter(firstpos))
1057 // now find the beginning by looking for a nonletter
1059 while ((firstpos>= 0) && IsLetter(firstpos))
1062 // the above is now pointing to the preceeding non-letter
1066 // so copy characters into theword until we get a nonletter
1067 // note that this can easily exceed lastpos, wich means
1068 // that if used in the middle of a word, the whole word
1071 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1079 #warning Remember to get rid of this one. (Lgb)
1081 LyXParagraph::size_type LyXParagraph::Last() const
1084 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1085 return text.size() + NextAfterFootnote()->Last() + 1;
1086 // the 1 is the symbol
1095 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1097 // > because last is the next unused position, and you can
1098 // use it if you want
1101 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1102 return NextAfterFootnote()
1103 ->ParFromPos(pos - text.size() - 1);
1105 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1106 "position does not exist." << endl;
1115 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1117 // > because last is the next unused position, and you can
1118 // use it if you want
1121 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1122 return NextAfterFootnote()
1123 ->PositionInParFromPos(pos - text.size() - 1);
1126 "ERROR (LyXParagraph::PositionInParFromPos): "
1127 "position does not exist." << endl;
1136 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1137 LyXFont const & font)
1140 // > because last is the next unused position, and you can
1141 // use it if you want
1144 next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1145 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1148 lyxerr << "ERROR (LyXParagraph::SetFont): "
1149 "position does not exist." << endl;
1154 Assert(pos <= size());
1157 // First, reduce font against layout/label font
1158 // Update: The SetCharFont() routine in text2.C already
1159 // reduces font, so we don't need to do that here. (Asger)
1160 // No need to simplify this because it will disappear
1161 // in a new kernel. (Asger)
1162 // Next search font table
1164 FontTable search_font(pos, LyXFont());
1165 FontList::iterator it = lower_bound(fontlist.begin(),
1167 search_font, matchFT());
1168 unsigned int i = it - fontlist.begin();
1169 bool notfound = it == fontlist.end();
1171 if (!notfound && fontlist[i].font() == font)
1174 bool begin = pos == 0 || notfound ||
1175 (i > 0 && fontlist[i-1].pos() == pos - 1);
1176 // Is position pos is a beginning of a font block?
1177 bool end = !notfound && fontlist[i].pos() == pos;
1178 // Is position pos is the end of a font block?
1179 if (begin && end) { // A single char block
1180 if (i + 1 < fontlist.size() &&
1181 fontlist[i + 1].font() == font) {
1182 // Merge the singleton block with the next block
1183 fontlist.erase(fontlist.begin() + i);
1184 if (i > 0 && fontlist[i - 1].font() == font)
1185 fontlist.erase(fontlist.begin() + i-1);
1186 } else if (i > 0 && fontlist[i - 1].font() == font) {
1187 // Merge the singleton block with the previous block
1188 fontlist[i - 1].pos(pos);
1189 fontlist.erase(fontlist.begin() + i);
1191 fontlist[i].font(font);
1193 if (i > 0 && fontlist[i - 1].font() == font)
1194 fontlist[i - 1].pos(pos);
1196 fontlist.insert(fontlist.begin() + i,
1197 FontTable(pos, font));
1199 fontlist[i].pos(pos - 1);
1200 if (!(i + 1 < fontlist.size() &&
1201 fontlist[i + 1].font() == font))
1202 fontlist.insert(fontlist.begin() + i + 1,
1203 FontTable(pos, font));
1204 } else { // The general case. The block is splitted into 3 blocks
1205 fontlist.insert(fontlist.begin() + i,
1206 FontTable(pos - 1, fontlist[i].font()));
1207 fontlist.insert(fontlist.begin() + i + 1,
1208 FontTable(pos, font));
1214 void LyXParagraph::next(LyXParagraph * p)
1220 // This function is able to hide closed footnotes.
1221 LyXParagraph * LyXParagraph::next()
1224 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1225 LyXParagraph * tmp = next_;
1227 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1229 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1230 return tmp->next(); /* there can be more than one
1231 footnote in a logical
1234 return next_; // This should never happen!
1241 LyXParagraph const * LyXParagraph::next() const
1244 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1245 LyXParagraph * tmp = next_;
1247 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1249 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1250 return tmp->next(); /* there can be more than one
1251 footnote in a logical
1254 return next_; // This should never happen!
1262 LyXParagraph * LyXParagraph::NextAfterFootnote()
1264 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1265 LyXParagraph * tmp = next_;
1266 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1268 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1269 return tmp; /* there can be more than one footnote
1270 in a logical paragraph */
1272 return next_; // This should never happen!
1280 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1282 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1283 LyXParagraph * tmp = next_;
1284 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1286 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1287 return tmp; /* there can be more than one footnote
1288 in a logical paragraph */
1290 return next_; // This should never happen!
1298 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1301 if (previous_ && previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1303 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1304 tmp = tmp->previous_;
1305 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1306 return tmp; /* there can be more than one footnote
1307 in a logical paragraph */
1309 return previous_; // This should never happen!
1317 LyXParagraph * LyXParagraph::LastPhysicalPar()
1319 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1322 LyXParagraph * tmp = this;
1324 && tmp->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1325 tmp = tmp->NextAfterFootnote();
1333 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1335 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1338 LyXParagraph const * tmp = this;
1340 && tmp->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1341 tmp = tmp->NextAfterFootnote();
1349 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1353 LyXParagraph * tmppar = this;
1357 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1358 tmppar = tmppar->previous_;
1369 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1373 LyXParagraph const * tmppar = this;
1377 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1378 tmppar = tmppar->previous_;
1388 void LyXParagraph::previous(LyXParagraph * p)
1394 // This function is able to hide closed footnotes.
1395 LyXParagraph * LyXParagraph::previous()
1398 LyXParagraph * tmp = previous_;
1403 && tmp->previous_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1404 tmp = tmp->previous_;
1406 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1407 tmp = tmp->previous_;
1408 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1409 return tmp->next_->previous();
1419 // This function is able to hide closed footnotes.
1420 LyXParagraph const * LyXParagraph::previous() const
1423 LyXParagraph * tmp = previous_;
1427 && tmp->previous_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1428 tmp = tmp->previous_;
1430 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1431 tmp = tmp->previous_;
1432 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1433 return tmp->next_->previous();
1443 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1444 LyXParagraph::size_type pos,
1449 // create a new paragraph
1452 size_type pos_first;
1453 LyXParagraph * par = ParFromPos(pos);
1454 LyXParagraph * firstpar = FirstPhysicalPar();
1456 LyXParagraph * tmp = new LyXParagraph(par);
1458 //LyXParagraph * par = this;
1459 //LyXParagraph * firstpar = this;
1460 LyXParagraph * tmp = new LyXParagraph(this);
1464 tmp->footnoteflag = footnoteflag;
1465 tmp->footnotekind = footnotekind;
1467 // this is an idea for a more userfriendly layout handling, I will
1468 // see what the users say
1471 // layout stays the same with latex-environments
1473 tmp->SetOnlyLayout(bparams, firstpar->layout);
1474 tmp->SetLabelWidthString(firstpar->params.labelWidthString());
1477 // layout stays the same with latex-environments
1479 tmp->SetOnlyLayout(bparams, layout);
1480 tmp->SetLabelWidthString(params.labelWidthString());
1484 if (Last() > pos || !Last() || flag == 2) {
1485 tmp->SetOnlyLayout(bparams, firstpar->layout);
1486 tmp->params.align(firstpar->params.align());
1487 tmp->SetLabelWidthString(firstpar->params.labelWidthString());
1489 tmp->params.lineBottom(firstpar->params.lineBottom());
1490 firstpar->params.lineBottom(false);
1491 tmp->params.pagebreakBottom(firstpar->params.pagebreakBottom());
1492 firstpar->params.pagebreakBottom(false);
1493 tmp->params.spaceBottom(firstpar->params.spaceBottom());
1494 firstpar->params.spaceBottom(VSpace(VSpace::NONE));
1496 tmp->params.depth(firstpar->params.depth());
1497 tmp->params.noindent(firstpar->params.noindent());
1499 if (Last() > pos || !Last() || flag == 2) {
1500 tmp->SetOnlyLayout(bparams, layout);
1501 tmp->params.align(params.align());
1502 tmp->SetLabelWidthString(params.labelWidthString());
1504 tmp->params.lineBottom(params.lineBottom());
1505 params.lineBottom(false);
1506 tmp->params.pagebreakBottom(params.pagebreakBottom());
1507 params.pagebreakBottom(false);
1508 tmp->params.spaceBottom(params.spaceBottom());
1509 params.spaceBottom(VSpace(VSpace::NONE));
1511 tmp->params.depth(params.depth());
1512 tmp->params.noindent(params.noindent());
1514 // copy everything behind the break-position
1515 // to the new paragraph
1518 while (ParFromPos(pos_first) != par)
1520 pos_end = pos_first + par->text.size() - 1;
1523 for (i = j = pos; i <= pos_end; ++i) {
1524 par->CutIntoMinibuffer(bparams, i - pos_first);
1525 if (tmp->InsertFromMinibuffer(j - pos))
1531 for (i = pos_end; i >= pos; --i)
1532 par->Erase(i - pos_first);
1536 size_type pos_end = text.size() - 1;
1538 for (i = j = pos; i <= pos_end; ++i) {
1539 CutIntoMinibuffer(bparams, i);
1540 if (tmp->InsertFromMinibuffer(j - pos))
1544 for (i = pos_end; i >= pos; --i)
1552 // just an idea of me
1554 tmp->params.lineTop(firstpar->params.lineTop());
1555 tmp->params.pagebreakTop(firstpar->params.pagebreakTop());
1556 tmp->params.spaceTop(firstpar->params.spaceTop());
1557 tmp->bibkey = firstpar->bibkey;
1559 // layout stays the same with latex-environments
1561 firstpar->SetOnlyLayout(bparams, tmp->layout);
1562 firstpar->SetLabelWidthString(tmp->params.labelWidthString());
1563 firstpar->params.depth(tmp->params.depth());
1567 // just an idea of me
1569 tmp->params.lineTop(params.lineTop());
1570 tmp->params.pagebreakTop(params.pagebreakTop());
1571 tmp->params.spaceTop(params.spaceTop());
1572 tmp->bibkey = bibkey;
1574 // layout stays the same with latex-environments
1576 SetOnlyLayout(bparams, tmp->layout);
1577 SetLabelWidthString(tmp->params.labelWidthString());
1578 params.depth(tmp->params.depth());
1585 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1588 par = par->FirstPhysicalPar();
1589 footnoteflag = par->footnoteflag;
1590 footnotekind = par->footnotekind;
1592 layout = par->layout;
1593 params.makeSame(par->params);
1595 // This can be changed after NEW_INSETS is in effect. (Lgb)
1596 SetLabelWidthString(par->params.labelWidthString());
1601 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1603 LyXParagraph * tmppar = this;
1606 && tmppar->previous_->footnoteflag ==
1607 LyXParagraph::CLOSED_FOOTNOTE)
1608 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1609 tmppar = tmppar->previous_;
1612 return this; // This should never happen!
1619 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1621 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1629 && (IsNewline(0) || IsLineSeparator(0))){
1640 LyXParagraph * LyXParagraph::Clone() const
1642 // create a new paragraph
1643 LyXParagraph * result = new LyXParagraph;
1645 result->MakeSameLayout(this);
1647 // this is because of the dummy layout of the paragraphs that
1649 result->layout = layout;
1651 result->inset_owner = inset_owner;
1655 result->bibkey = static_cast<InsetBibKey *>
1656 (bibkey->Clone(*current_view->buffer()));
1660 // copy everything behind the break-position to the new paragraph
1662 result->text = text;
1663 result->fontlist = fontlist;
1664 result->insetlist = insetlist;
1665 for (InsetList::iterator it = result->insetlist.begin();
1666 it != result->insetlist.end(); ++it)
1667 (*it).inset = (*it).inset->Clone(*current_view->buffer());
1672 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1675 par = par->FirstPhysicalPar();
1680 par->footnoteflag == footnoteflag &&
1681 par->footnotekind == footnotekind &&
1683 par->layout == layout &&
1684 params.sameLayout(par->params);
1688 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1689 LyXParagraph::size_type pos)
1692 // create a new paragraph
1693 LyXParagraph * par = ParFromPos(pos);
1695 LyXParagraph * tmp = new LyXParagraph(par);
1697 tmp->MakeSameLayout(par);
1699 // When can pos < Last()?
1700 // I guess pos == Last() is possible.
1702 // copy everything behind the break-position to the new
1704 size_type pos_first = 0;
1705 while (ParFromPos(pos_first) != par)
1707 size_type pos_end = pos_first + par->text.size() - 1;
1710 for (i = j = pos; i <= pos_end; ++i) {
1711 par->CutIntoMinibuffer(bparams, i - pos_first);
1712 if (tmp->InsertFromMinibuffer(j - pos))
1718 for (size_type i = pos_end; i >= pos; --i)
1719 par->Erase(i - pos_first);
1724 // create a new paragraph
1725 LyXParagraph * tmp = new LyXParagraph(this);
1726 tmp->MakeSameLayout(this);
1728 // When can pos > Last()?
1729 // I guess pos == Last() is possible.
1731 // copy everything behind the break-position to the new
1733 size_type pos_end = text.size() - 1;
1736 for (i = j = pos; i <= pos_end; ++i) {
1737 CutIntoMinibuffer(bparams, i);
1738 if (tmp->InsertFromMinibuffer(j - pos))
1744 for (size_type i = pos_end; i >= pos; --i)
1753 // Be carefull, this does not make any check at all.
1754 // This method has wrong name, it combined this par with the next par.
1755 // In that sense it is the reverse of break paragraph. (Lgb)
1756 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1758 // copy the next paragraph to this one
1759 LyXParagraph * the_next = next();
1761 LyXParagraph * firstpar = FirstPhysicalPar();
1764 // first the DTP-stuff
1766 firstpar->params.lineBottom(the_next->params.lineBottom());
1767 firstpar->params.spaceBottom(the_next->params.spaceBottom());
1768 firstpar->params.pagebreakBottom(the_next->params.pagebreakBottom());
1770 params.lineBottom(the_next->params.lineBottom());
1771 params.spaceBottom(the_next->params.spaceBottom());
1772 params.pagebreakBottom(the_next->params.pagebreakBottom());
1775 size_type pos_end = the_next->text.size() - 1;
1776 size_type pos_insert = Last();
1778 // ok, now copy the paragraph
1780 for (i = j = 0; i <= pos_end; ++i) {
1781 the_next->CutIntoMinibuffer(bparams, i);
1782 if (InsertFromMinibuffer(pos_insert + j))
1786 // delete the next paragraph
1787 LyXParagraph * ppar = the_next->previous_;
1788 LyXParagraph * npar = the_next->next_;
1795 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1797 LyXParagraph * par = ParFromPos(pos);
1799 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1800 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1806 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1808 LyXParagraph * par = ParFromPos(pos);
1810 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1811 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1818 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1820 LyXParagraph const * par = this;
1821 int par_depth = GetDepth();
1823 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1824 int const endlabeltype =
1825 textclasslist.Style(bparams.textclass,
1826 layout).endlabeltype;
1827 if (endlabeltype != END_LABEL_NO_LABEL) {
1828 LyXParagraph const * last = this;
1830 if (footnoteflag == NO_FOOTNOTE)
1831 last = LastPhysicalPar();
1832 else if (next_->footnoteflag == NO_FOOTNOTE)
1833 return endlabeltype;
1838 if (!last || !last->next_)
1839 return endlabeltype;
1841 int next_depth = last->next_->GetDepth();
1842 if (par_depth > next_depth ||
1843 (par_depth == next_depth && layout != last->next_->GetLayout() ))
1844 return endlabeltype;
1849 par = par->DepthHook(par_depth - 1);
1851 par_depth = par->GetDepth();
1853 return END_LABEL_NO_LABEL;
1857 LyXTextClass::size_type LyXParagraph::GetLayout() const
1860 return FirstPhysicalPar()->layout;
1867 char LyXParagraph::GetDepth() const
1870 return FirstPhysicalPar()->params.depth();
1872 return params.depth();
1877 char LyXParagraph::GetAlign() const
1880 return FirstPhysicalPar()->params.align();
1882 return params.align();
1887 string const & LyXParagraph::GetLabelstring() const
1890 return FirstPhysicalPar()->params.labelString();
1892 return params.labelString();
1897 int LyXParagraph::GetFirstCounter(int i) const
1900 return FirstPhysicalPar()->counter_[i];
1907 // the next two functions are for the manual labels
1908 string const LyXParagraph::GetLabelWidthString() const
1911 if (!FirstPhysicalPar()->params.labelWidthString().empty())
1912 return FirstPhysicalPar()->params.labelWidthString();
1914 if (!params.labelWidthString().empty())
1915 return params.labelWidthString();
1918 return _("Senseless with this layout!");
1922 void LyXParagraph::SetLabelWidthString(string const & s)
1925 LyXParagraph * par = FirstPhysicalPar();
1927 par->params.labelWidthString(s);
1929 params.labelWidthString(s);
1934 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1935 LyXTextClass::size_type new_layout)
1938 LyXParagraph * par = FirstPhysicalPar();
1940 LyXParagraph * par = this;
1942 LyXParagraph * ppar = 0;
1943 LyXParagraph * npar = 0;
1945 par->layout = new_layout;
1947 if (par->params.pextraType() == PEXTRA_NONE) {
1948 if (par->previous()) {
1950 ppar = par->previous()->FirstPhysicalPar();
1952 ppar = par->previous();
1956 && (ppar->params.depth() > par->params.depth()))
1958 ppar = ppar->previous()->FirstPhysicalPar();
1960 ppar = ppar->previous();
1965 npar = par->next()->NextAfterFootnote();
1971 && (npar->params.depth() > par->params.depth()))
1973 npar = npar->next()->NextAfterFootnote();
1975 npar = npar->next();
1978 if (ppar && (ppar->params.pextraType() != PEXTRA_NONE)) {
1979 string p1 = ppar->params.pextraWidth();
1980 string p2 = ppar->params.pextraWidthp();
1981 ppar->SetPExtraType(bparams,
1982 ppar->params.pextraType(),
1985 if ((par->params.pextraType() == PEXTRA_NONE) &&
1986 npar && (npar->params.pextraType() != PEXTRA_NONE)) {
1987 string const p1 = npar->params.pextraWidth();
1988 string const p2 = npar->params.pextraWidthp();
1989 npar->SetPExtraType(bparams, npar->params.pextraType(),
1996 void LyXParagraph::SetLayout(BufferParams const & bparams,
1997 LyXTextClass::size_type new_layout)
2001 * par = FirstPhysicalPar(),
2008 par->layout = new_layout;
2009 par->params.labelWidthString(string());
2010 par->params.align(LYX_ALIGN_LAYOUT);
2011 par->params.spaceTop(VSpace(VSpace::NONE));
2012 par->params.spaceBottom(VSpace(VSpace::NONE));
2013 par->params.spacing(Spacing(Spacing::Default));
2015 if (par->params.pextraType() == PEXTRA_NONE) {
2016 if (par->previous()) {
2018 ppar = par->previous()->FirstPhysicalPar();
2020 ppar = par->previous();
2024 && (ppar->params.depth() > par->params.depth()))
2026 ppar = ppar->previous()->FirstPhysicalPar();
2028 ppar = ppar->previous();
2033 npar = par->next()->NextAfterFootnote();
2039 && (npar->params.depth() > par->params.depth()))
2041 npar = npar->next()->NextAfterFootnote();
2043 npar = npar->next();
2046 if (ppar && (ppar->params.pextraType() != PEXTRA_NONE)) {
2047 string const p1 = ppar->params.pextraWidth();
2048 string const p2 = ppar->params.pextraWidthp();
2049 ppar->SetPExtraType(bparams, ppar->params.pextraType(),
2052 if ((par->params.pextraType() == PEXTRA_NONE) &&
2053 npar && (npar->params.pextraType() != PEXTRA_NONE)) {
2054 string const p1 = npar->params.pextraWidth();
2055 string const p2 = npar->params.pextraWidthp();
2056 npar->SetPExtraType(bparams, npar->params.pextraType(),
2063 // if the layout of a paragraph contains a manual label, the beginning of the
2064 // main body is the beginning of the second word. This is what the par-
2065 // function returns. If the layout does not contain a label, the main
2066 // body always starts with position 0. This differentiation is necessary,
2067 // because there cannot be a newline or a blank <= the beginning of the
2068 // main body in TeX.
2070 int LyXParagraph::BeginningOfMainBody() const
2073 if (FirstPhysicalPar() != this)
2076 // Unroll the first two cycles of the loop
2077 // and remember the previous character to
2078 // remove unnecessary GetChar() calls
2081 && GetChar(i) != LyXParagraph::META_NEWLINE
2084 char previous_char = 0;
2087 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2088 // Yes, this ^ is supposed to be "= " not "=="
2091 && previous_char != ' '
2092 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2094 previous_char = temp;
2100 if (i == 0 && i == size() &&
2101 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2102 && next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2103 ++i; /* the cursor should not jump
2104 * to the main body if there
2111 LyXParagraph * LyXParagraph::DepthHook(int deth)
2113 LyXParagraph * newpar = this;
2119 newpar = newpar->FirstPhysicalPar()->previous();
2121 newpar = newpar->previous();
2123 } while (newpar && newpar->GetDepth() > deth
2125 && newpar->footnoteflag == footnoteflag
2130 if (previous() || GetDepth())
2131 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2136 return newpar->FirstPhysicalPar();
2143 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2145 LyXParagraph const * 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 int LyXParagraph::AutoDeleteInsets()
2178 InsetList::size_type index = 0;
2179 while (index < insetlist.size()) {
2180 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2181 Erase(insetlist[index].pos);
2182 // Erase() calls to insetlist.erase(&insetlist[index])
2183 // so index shouldn't be increased.
2192 LyXParagraph::inset_iterator
2193 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2195 InsetTable search_inset(pos, 0);
2196 InsetList::iterator it = lower_bound(insetlist.begin(),
2198 search_inset, matchIT());
2199 return inset_iterator(it);
2203 // returns -1 if inset not found
2204 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2207 for (InsetList::const_iterator cit = insetlist.begin();
2208 cit != insetlist.end(); ++cit) {
2209 if ((*cit).inset == inset) {
2213 if (inset == bibkey)
2217 // Think about footnotes.
2218 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2219 && next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2221 NextAfterFootnote()->GetPositionOfInset(inset);
2223 return text.size() + 1 + further;
2230 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2231 BufferParams const & bparams,
2232 ostream & os, TexRow & texrow,
2237 TexRow & foot_texrow,
2242 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2243 LyXLayout const & style =
2244 textclasslist.Style(bparams.textclass,
2247 bool further_blank_line = false;
2250 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2253 if (params.startOfAppendix()) {
2254 os << "\\appendix\n";
2258 if (!params.spacing().isDefault()
2259 && (!previous() || !previous()->HasSameLayout(this))) {
2260 os << params.spacing().writeEnvirBegin() << "\n";
2264 if (tex_code_break_column && style.isCommand()){
2269 if (params.pagebreakTop()) {
2271 further_blank_line = true;
2273 if (params.spaceTop().kind() != VSpace::NONE) {
2274 os << params.spaceTop().asLatexCommand(bparams);
2275 further_blank_line = true;
2278 if (params.lineTop()) {
2279 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2280 << "\\vspace{-1\\parskip}";
2281 further_blank_line = true;
2284 if (further_blank_line){
2289 Language const * language = getParLanguage(bparams);
2290 Language const * doc_language = bparams.language;
2291 Language const * previous_language = previous_
2292 ? previous_->getParLanguage(bparams) : doc_language;
2293 if (language->babel() != doc_language->babel() &&
2294 language->babel() != previous_language->babel()) {
2295 os << subst(lyxrc.language_command_begin, "$$lang",
2301 if (bparams.inputenc == "auto" &&
2302 language->encoding() != previous_language->encoding()) {
2303 os << "\\inputencoding{"
2304 << language->encoding()->LatexName()
2309 switch (style.latextype) {
2312 << style.latexname()
2313 << style.latexparam();
2315 case LATEX_ITEM_ENVIRONMENT:
2317 bibkey->Latex(buf, os, false, false);
2321 case LATEX_LIST_ENVIRONMENT:
2328 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2330 LyXParagraph * par = next_;
2332 // Spit out footnotes
2333 if (lyxrc.rtl_support) {
2334 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
2335 && next_->footnoteflag != footnoteflag) {
2336 LyXParagraph * p = 0;
2337 bool is_rtl = (size() > 0)
2338 ? GetFontSettings(bparams,
2339 size()-1).isRightToLeft()
2340 : language->RightToLeft();
2341 if ((p = NextAfterFootnote()) != 0 &&
2343 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2344 is_rtl = getParLanguage(bparams)->RightToLeft();
2345 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2346 && par->footnoteflag != footnoteflag) {
2347 par = par->TeXFootnote(buf, bparams,
2349 foot_texrow, foot_count,
2351 par->SimpleTeXOnePar(buf, bparams,
2352 os, texrow, moving_arg);
2353 is_rtl = (par->size() > 0)
2354 ? par->GetFontSettings(bparams,
2355 par->size()-1).isRightToLeft()
2356 : language->RightToLeft();
2358 par->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2359 (p = par->NextAfterFootnote()) != 0 &&
2361 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2362 is_rtl = language->RightToLeft();
2367 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2368 && par->footnoteflag != footnoteflag) {
2369 par = par->TeXFootnote(buf, bparams,
2371 foot, foot_texrow, foot_count,
2373 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2379 // Make sure that \\par is done with the font of the last
2380 // character if this has another size as the default.
2381 // This is necessary because LaTeX (and LyX on the screen)
2382 // calculates the space between the baselines according
2383 // to this font. (Matthias)
2385 // Is this really needed ? (Dekel)
2386 // We do not need to use to change the font for the last paragraph
2387 // or for a command.
2388 LyXFont font = getFont(bparams, Last() - 1);
2389 bool is_command = textclasslist.Style(bparams.textclass,
2390 GetLayout()).isCommand();
2391 if (style.resfont.size() != font.size() && next_ && !is_command) {
2394 os << "\\" << font.latexSize() << " \\par}";
2395 } else if (need_par) {
2397 } else if (is_command)
2400 if (language->babel() != doc_language->babel() &&
2403 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2405 || par->getParLanguage(bparams)->babel() != language->babel())) {
2407 << subst(lyxrc.language_command_end, "$$lang",
2408 doc_language->babel());
2411 switch (style.latextype) {
2412 case LATEX_ITEM_ENVIRONMENT:
2413 case LATEX_LIST_ENVIRONMENT:
2414 if (par && (params.depth() < par->params.depth())) {
2419 case LATEX_ENVIRONMENT:
2420 // if its the last paragraph of the current environment
2421 // skip it otherwise fall through
2423 && (par->layout != layout
2424 || par->params.depth() != params.depth()
2425 || par->params.pextraType() != params.pextraType()))
2428 // we don't need it for the last paragraph!!!
2429 // or for tables in floats
2430 // -- effectively creates a \par where there isn't one which
2431 // breaks a \subfigure or \subtable.
2433 // && footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2439 further_blank_line = false;
2440 if (params.lineBottom()) {
2441 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2442 further_blank_line = true;
2445 if (params.spaceBottom().kind() != VSpace::NONE) {
2446 os << params.spaceBottom().asLatexCommand(bparams);
2447 further_blank_line = true;
2450 if (params.pagebreakBottom()) {
2452 further_blank_line = true;
2455 if (further_blank_line){
2460 if (!params.spacing().isDefault()
2461 && (!par || !par->HasSameLayout(this))) {
2462 os << params.spacing().writeEnvirEnd() << "\n";
2466 // we don't need it for the last paragraph!!!
2469 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2470 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2477 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2482 // This one spits out the text of the paragraph
2483 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2484 BufferParams const & bparams,
2485 ostream & os, TexRow & texrow,
2488 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2490 bool return_value = false;
2492 LyXLayout const & style =
2493 textclasslist.Style(bparams.textclass,
2495 LyXFont basefont, last_font;
2497 // Maybe we have to create a optional argument.
2498 size_type main_body;
2499 if (style.labeltype != LABEL_MANUAL)
2502 main_body = BeginningOfMainBody();
2504 if (main_body > 0) {
2506 basefont = getFont(bparams, -2); // Get label font
2508 basefont = getFont(bparams, -1); // Get layout font
2519 if (style.isCommand()) {
2522 } else if (params.align() != LYX_ALIGN_LAYOUT) {
2525 return_value = true;
2529 moving_arg |= style.needprotect;
2531 // Which font is currently active?
2532 LyXFont running_font(basefont);
2533 // Do we have an open font change?
2534 bool open_font = false;
2536 texrow.start(this, 0);
2538 for (size_type i = 0; i < size(); ++i) {
2540 // First char in paragraph or after label?
2546 if (main_body > 0) {
2548 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2551 basefont = getFont(bparams, -1); // Now use the layout font
2552 running_font = basefont;
2556 if (style.isCommand()) {
2559 } else if (params.align() != LYX_ALIGN_LAYOUT && next_) {
2560 // We do not need \par here (Dekel)
2564 return_value = true;
2567 if (params.noindent()) {
2568 os << "\\noindent ";
2571 switch (params.align()) {
2572 case LYX_ALIGN_NONE:
2573 case LYX_ALIGN_BLOCK:
2574 case LYX_ALIGN_LAYOUT:
2575 case LYX_ALIGN_SPECIAL:
2577 case LYX_ALIGN_LEFT:
2580 if (getParLanguage(bparams)->babel() != "hebrew") {
2581 os << "\\raggedright ";
2584 os << "\\raggedleft ";
2588 case LYX_ALIGN_RIGHT:
2591 if (getParLanguage(bparams)->babel() != "hebrew") {
2592 os << "\\raggedleft ";
2595 os << "\\raggedright ";
2599 case LYX_ALIGN_CENTER:
2602 os << "\\centering ";
2608 value_type c = GetChar(i);
2610 // Fully instantiated font
2611 LyXFont font = getFont(bparams, i);
2613 LyXParagraph * p = 0;
2616 previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2617 (p = PreviousBeforeFootnote()) != 0)
2618 last_font = p->getFont(bparams, p->size() - 1);
2621 last_font = running_font;
2623 // Spaces at end of font change are simulated to be
2624 // outside font change, i.e. we write "\textXX{text} "
2625 // rather than "\textXX{text }". (Asger)
2626 if (open_font && c == ' ' && i <= size() - 2
2627 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2628 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2629 font = getFont(bparams, i + 1);
2631 // We end font definition before blanks
2632 if (!font.equalExceptLatex(running_font) && open_font) {
2633 column += running_font.latexWriteEndChanges(os,
2635 (i == main_body-1) ? basefont : font);
2636 running_font = basefont;
2640 // Blanks are printed before start of fontswitch
2642 // Do not print the separation of the optional argument
2643 if (i != main_body - 1) {
2644 SimpleTeXBlanks(os, texrow, i,
2645 column, font, style);
2649 // Do we need to change font?
2650 if (!font.equalExceptLatex(running_font)
2651 && i != main_body-1) {
2652 column += font.latexWriteStartChanges(os, basefont,
2654 running_font = font;
2658 if (c == LyXParagraph::META_NEWLINE) {
2659 // newlines are handled differently here than
2660 // the default in SimpleTeXSpecialChars().
2661 if (!style.newline_allowed
2662 || font.latex() == LyXFont::ON) {
2666 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2669 basefont = getFont(bparams, -1);
2670 running_font = basefont;
2671 if (font.family() ==
2672 LyXFont::TYPEWRITER_FAMILY) {
2680 texrow.start(this, i + 1);
2683 SimpleTeXSpecialChars(buf, bparams,
2684 os, texrow, moving_arg,
2685 font, running_font, basefont,
2686 open_font, style, i, column, c);
2690 // If we have an open font definition, we have to close it
2692 LyXParagraph * p = 0;
2695 && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
2696 && (p = NextAfterFootnote()) != 0
2701 running_font.latexWriteEndChanges(os, basefont,
2702 p->getFont(bparams, 0));
2704 running_font.latexWriteEndChanges(os, basefont, basefont);
2707 // Needed if there is an optional argument but no contents.
2708 if (main_body > 0 && main_body == size()) {
2710 return_value = false;
2713 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2714 return return_value;
2718 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2720 bool retval = false;
2722 case LyXParagraph::META_HFILL:
2723 sgml_string.erase();
2725 case LyXParagraph::META_NEWLINE:
2729 sgml_string = "&";
2732 sgml_string = "<";
2735 sgml_string = ">";
2738 sgml_string = "$";
2741 sgml_string = "#";
2744 sgml_string = "%";
2747 sgml_string = "[";
2750 sgml_string = "]";
2753 sgml_string = "{";
2756 sgml_string = "}";
2759 sgml_string = "˜";
2762 sgml_string = """;
2765 sgml_string = "\";
2771 case '\0': // Ignore :-)
2772 sgml_string.erase();
2782 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
2783 LyXParagraph::size_type const i,
2784 int & column, LyXFont const & font,
2785 LyXLayout const & style)
2787 if (column > tex_code_break_column
2789 && GetChar(i - 1) != ' '
2791 // In LaTeX mode, we don't want to
2792 // break lines since some commands
2794 && ! (font.latex() == LyXFont::ON)
2795 // same in FreeSpacing mode
2796 && !style.free_spacing
2797 // In typewriter mode, we want to avoid
2798 // ! . ? : at the end of a line
2799 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
2800 && (GetChar(i-1) == '.'
2801 || GetChar(i-1) == '?'
2802 || GetChar(i-1) == ':'
2803 || GetChar(i-1) == '!'))) {
2804 if (tex_code_break_column == 0) {
2805 // in batchmode we need LaTeX to still
2806 // see it as a space not as an extra '\n'
2812 texrow.start(this, i + 1);
2814 } else if (font.latex() == LyXFont::OFF) {
2815 if (style.free_spacing) {
2824 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
2825 BufferParams const & bparams,
2826 ostream & os, TexRow & texrow,
2829 LyXFont & running_font,
2832 LyXLayout const & style,
2833 LyXParagraph::size_type & i,
2835 LyXParagraph::value_type const c)
2837 // Two major modes: LaTeX or plain
2838 // Handle here those cases common to both modes
2839 // and then split to handle the two modes separately.
2841 case LyXParagraph::META_INSET: {
2842 Inset * inset = GetInset(i);
2845 int const len = os.tellp();
2846 //ostream::pos_type const len = os.tellp();
2847 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
2848 || inset->LyxCode() == Inset::MATH_CODE
2849 || inset->LyxCode() == Inset::URL_CODE)
2850 && running_font.isRightToLeft()) {
2855 int tmp = inset->Latex(buf, os, moving_arg,
2856 style.free_spacing);
2864 column += int(os.tellp()) - len;
2873 case LyXParagraph::META_NEWLINE:
2875 column += running_font.latexWriteEndChanges(os,
2880 basefont = getFont(bparams, -1);
2881 running_font = basefont;
2884 case LyXParagraph::META_HFILL:
2890 // And now for the special cases within each mode
2891 // Are we in LaTeX mode?
2892 if (font.latex() == LyXFont::ON) {
2893 // at present we only have one option
2894 // but I'll leave it as a switch statement
2895 // so its simpler to extend. (ARRae)
2898 // make sure that we will not print
2899 // error generating chars to the tex
2900 // file. This test would not be needed
2901 // if it were done in the buffer
2909 // Plain mode (i.e. not LaTeX)
2912 os << "\\textbackslash{}";
2916 case '°': case '±': case '²': case '³':
2917 case '×': case '÷': case '¹': case 'ª':
2918 case 'º': case '¬': case 'µ':
2919 if (bparams.inputenc == "latin1" ||
2920 (bparams.inputenc == "auto" &&
2921 font.language()->encoding()->LatexName()
2923 os << "\\ensuremath{"
2932 case '|': case '<': case '>':
2933 // In T1 encoding, these characters exist
2934 if (lyxrc.fontenc == "T1") {
2936 //... but we should avoid ligatures
2937 if ((c == '>' || c == '<')
2939 && GetChar(i + 1) == c) {
2940 //os << "\\textcompwordmark{}";
2941 // Jean-Marc, have a look at
2942 // this. IÂ think this works
2950 // Typewriter font also has them
2951 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
2955 // Otherwise, we use what LaTeX
2959 os << "\\textless{}";
2963 os << "\\textgreater{}";
2967 os << "\\textbar{}";
2973 case '-': // "--" in Typewriter mode -> "-{}-"
2975 && GetChar(i + 1) == '-'
2976 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
2985 os << "\\char`\\\"{}";
2990 if (bparams.inputenc == "default") {
2999 case '%': case '#': case '{':
3006 os << "\\textasciitilde{}";
3011 os << "\\textasciicircum{}";
3015 case '*': case '[': case ']':
3016 // avoid being mistaken for optional arguments
3017 os << '{' << c << '}';
3022 // Blanks are printed before font switching.
3023 // Sure? I am not! (try nice-latex)
3024 // I am sure it's correct. LyX might be smarter
3025 // in the future, but for now, nothing wrong is
3030 /* idea for labels --- begin*/
3034 && font.family() != LyXFont::TYPEWRITER_FAMILY
3035 && GetChar(i + 1) == 'y'
3036 && GetChar(i + 2) == 'X') {
3044 && font.family() != LyXFont::TYPEWRITER_FAMILY
3045 && GetChar(i + 1) == 'e'
3046 && GetChar(i + 2) == 'X') {
3051 // Check for "LaTeX2e"
3054 && font.family() != LyXFont::TYPEWRITER_FAMILY
3055 && GetChar(i + 1) == 'a'
3056 && GetChar(i + 2) == 'T'
3057 && GetChar(i + 3) == 'e'
3058 && GetChar(i + 4) == 'X'
3059 && GetChar(i + 5) == '2'
3060 && GetChar(i + 6) == 'e') {
3065 // Check for "LaTeX"
3068 && font.family() != LyXFont::TYPEWRITER_FAMILY
3069 && GetChar(i + 1) == 'a'
3070 && GetChar(i + 2) == 'T'
3071 && GetChar(i + 3) == 'e'
3072 && GetChar(i + 4) == 'X') {
3076 /* idea for labels --- end*/
3077 } else if (c != '\0') {
3087 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3088 BufferParams const & bparams,
3089 ostream & os, TexRow & texrow
3092 TexRow & foot_texrow,
3097 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3098 LyXParagraph * par = this;
3101 (par->params.depth() == params.depth())
3103 && (par->footnoteflag == footnoteflag)
3108 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3110 if (textclasslist.Style(bparams.textclass,
3111 par->layout).isEnvironment()
3112 || par->params.pextraType() != PEXTRA_NONE) {
3113 par = par->TeXEnvironment(buf, bparams,
3121 par = par->TeXOnePar(buf, bparams,
3131 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3137 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3138 BufferParams const & bparams,
3139 ostream & os, TexRow & texrow
3142 TexRow & foot_texrow,
3147 bool eindent_open = false;
3149 bool foot_this_level = false;
3151 // flags when footnotetext should be appended to file.
3152 static bool minipage_open = false;
3153 static int minipage_open_depth = 0;
3154 char par_sep = bparams.paragraph_separation;
3156 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3159 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3162 LyXLayout const & style =
3163 textclasslist.Style(bparams.textclass,
3166 if (params.pextraType() == PEXTRA_INDENT) {
3167 if (!params.pextraWidth().empty()) {
3168 os << "\\begin{LyXParagraphIndent}{"
3169 << params.pextraWidth() << "}\n";
3171 //float ib = atof(pextra_widthp.c_str())/100;
3172 // string can't handle floats at present (971109)
3173 // so I'll do a conversion by hand knowing that
3174 // the limits are 0.0 to 1.0. ARRae.
3175 os << "\\begin{LyXParagraphIndent}{";
3176 switch (params.pextraWidthp().length()) {
3182 << params.pextraWidthp();
3186 << params.pextraWidthp();
3188 os << "\\columnwidth}\n";
3191 eindent_open = true;
3193 if ((params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
3194 if (params.pextraHfill() && previous() &&
3195 (previous()->params.pextraType() == PEXTRA_MINIPAGE)) {
3196 os << "\\hfill{}\n";
3199 if (par_sep == BufferParams::PARSEP_INDENT) {
3200 os << "{\\setlength\\parindent{0pt}\n";
3203 os << "\\begin{minipage}";
3204 switch (params.pextraAlignment()) {
3205 case MINIPAGE_ALIGN_TOP:
3208 case MINIPAGE_ALIGN_MIDDLE:
3211 case MINIPAGE_ALIGN_BOTTOM:
3215 if (!params.pextraWidth().empty()) {
3216 os << '{' << params.pextraWidth() << "}\n";
3218 //float ib = atof(par->pextra_width.c_str())/100;
3219 // string can't handle floats at present
3220 // so I'll do a conversion by hand knowing that
3221 // the limits are 0.0 to 1.0. ARRae.
3223 switch (params.pextraWidthp().length()) {
3229 << params.pextraWidthp();
3233 << params.pextraWidthp();
3235 os << "\\columnwidth}\n";
3238 if (par_sep == BufferParams::PARSEP_INDENT) {
3239 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3242 minipage_open = true;
3243 minipage_open_depth = params.depth();
3246 #ifdef WITH_WARNINGS
3247 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3248 //I disabled it because it breaks when lists span on several
3251 if (style.isEnvironment()){
3252 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3253 #ifdef FANCY_FOOTNOTE_CODE
3254 if (foot_count < 0) {
3255 // flag that footnote[mark][text] should be
3256 // used for any footnotes from now on
3258 foot_this_level = true;
3261 os << "\\begin{" << style.latexname() << "}{"
3262 << params.labelWidthString() << "}\n";
3263 } else if (style.labeltype == LABEL_BIBLIO) {
3265 os << "\\begin{" << style.latexname() << "}{"
3266 << bibitemWidest(buf)
3268 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3269 #ifdef FANCY_FOOTNOTE_CODE
3270 if (foot_count < 0) {
3271 // flag that footnote[mark][text] should be
3272 // used for any footnotes from now on
3274 foot_this_level = true;
3277 os << "\\begin{" << style.latexname() << '}'
3278 << style.latexparam() << '\n';
3280 os << "\\begin{" << style.latexname() << '}'
3281 << style.latexparam() << '\n';
3284 LyXParagraph * par = this;
3286 par = par->TeXOnePar(buf, bparams,
3290 foot, foot_texrow, foot_count
3294 if (minipage_open && par && !style.isEnvironment() &&
3295 (par->params.pextraType() == PEXTRA_MINIPAGE) &&
3296 par->params.pextraStartMinipage()) {
3297 os << "\\end{minipage}\n";
3299 if (par_sep == BufferParams::PARSEP_INDENT) {
3303 minipage_open = false;
3305 if (par && par->params.depth() > params.depth()) {
3306 if (textclasslist.Style(bparams.textclass,
3307 par->layout).isParagraph()
3309 // How to handle this? (Lgb)
3310 //&& !suffixIs(os, "\n\n")
3312 // There should be at least one '\n' already
3313 // but we need there to be two for Standard
3314 // paragraphs that are depth-increment'ed to be
3315 // output correctly. However, tables can
3316 // also be paragraphs so don't adjust them.
3319 // Will it ever harm to have one '\n' too
3320 // many? i.e. that we sometimes will have
3321 // three in a row. (Lgb)
3325 par = par->TeXDeeper(buf, bparams, os, texrow
3327 ,foot, foot_texrow, foot_count
3331 if (par && par->layout == layout && par->params.depth() == params.depth() &&
3332 (par->params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
3333 if (par->params.pextraHfill() && par->previous() &&
3334 (par->previous()->params.pextraType() == PEXTRA_MINIPAGE)){
3335 os << "\\hfill{}\n";
3338 if (par_sep == BufferParams::PARSEP_INDENT) {
3339 os << "{\\setlength\\parindent{0pt}\n";
3342 os << "\\begin{minipage}";
3343 switch (par->params.pextraAlignment()) {
3344 case MINIPAGE_ALIGN_TOP:
3347 case MINIPAGE_ALIGN_MIDDLE:
3350 case MINIPAGE_ALIGN_BOTTOM:
3354 if (!par->params.pextraWidth().empty()) {
3355 os << '{' << par->params.pextraWidth() << "}\n";
3357 //float ib = atof(par->pextra_widthp.c_str())/100;
3358 // string can't handle floats at present
3359 // so I'll do a conversion by hand knowing that
3360 // the limits are 0.0 to 1.0. ARRae.
3362 switch (par->params.pextraWidthp().length()) {
3367 os << "0." << par->params.pextraWidthp();
3370 os << "0.0" << par->params.pextraWidthp();
3372 os << "\\columnwidth}\n";
3375 if (par_sep == BufferParams::PARSEP_INDENT) {
3376 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3379 minipage_open = true;
3380 minipage_open_depth = par->params.depth();
3383 && par->layout == layout
3384 && par->params.depth() == params.depth()
3385 && par->params.pextraType() == params.pextraType()
3387 && par->footnoteflag == footnoteflag
3391 if (style.isEnvironment()) {
3392 os << "\\end{" << style.latexname() << '}';
3394 // maybe this should go after the minipage closes?
3395 if (foot_this_level) {
3396 if (foot_count >= 1) {
3397 if (foot_count > 1) {
3398 os << "\\addtocounter{footnote}{-"
3403 texrow += foot_texrow;
3405 foot_texrow.reset();
3411 if (minipage_open && (minipage_open_depth == params.depth()) &&
3412 (!par || par->params.pextraStartMinipage() ||
3413 par->params.pextraType() != PEXTRA_MINIPAGE)) {
3414 os << "\\end{minipage}\n";
3416 if (par_sep == BufferParams::PARSEP_INDENT) {
3420 if (par && par->params.pextraType() != PEXTRA_MINIPAGE) {
3421 os << "\\medskip\n\n";
3425 minipage_open = false;
3428 os << "\\end{LyXParagraphIndent}\n";
3431 if (!(par && (par->params.pextraType() == PEXTRA_MINIPAGE)
3432 && par->params.pextraHfill())) {
3436 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3437 return par; // ale970302
3442 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3443 BufferParams const & bparams,
3444 ostream & os, TexRow & texrow,
3445 ostream & foot, TexRow & foot_texrow,
3449 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3450 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3451 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3452 "No footnote!" << endl;
3454 LyXParagraph * par = this;
3455 LyXLayout const & style =
3456 textclasslist.Style(bparams.textclass,
3457 previous_->GetLayout());
3459 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3460 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3461 "Float other than footnote in command"
3462 " with moving argument is illegal" << endl;
3465 if (footnotekind != LyXParagraph::FOOTNOTE
3466 && footnotekind != LyXParagraph::MARGIN
3469 // How to solve this?
3470 //&& !suffixIs(file, '\n')
3472 // we need to ensure that real floats like tables and figures
3473 // have their \begin{} on a new line otherwise we can get
3474 // incorrect results when using the endfloat.sty package
3475 // especially if two floats follow one another. ARRae 981022
3476 // NOTE: if the file is length 0 it must have just been
3477 // written out so we assume it ended with a '\n'
3479 // As far as I can see there is never any harm in writing
3480 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3485 bool moving_arg = false;
3486 bool need_closing = false;
3487 bool is_rtl = isRightToLeftPar(bparams);
3489 if (is_rtl != parent_is_rtl) {
3494 need_closing = true;
3497 bool footer_in_body = true;
3498 switch (footnotekind) {
3499 case LyXParagraph::FOOTNOTE:
3500 if (style.intitle) {
3501 os << "\\thanks{\n";
3502 footer_in_body = false;
3505 if (foot_count == -1) {
3506 // we're at depth 0 so we can use:
3507 os << "\\footnote{%\n";
3508 footer_in_body = false;
3510 os << "\\footnotemark{}%\n";
3512 // we only need this when there are
3513 // multiple footnotes
3514 os << "\\stepcounter{footnote}";
3516 os << "\\footnotetext{%\n";
3517 foot_texrow.start(this, 0);
3518 foot_texrow.newline();
3523 case LyXParagraph::MARGIN:
3524 os << "\\marginpar{\n";
3526 case LyXParagraph::FIG:
3527 if (params.pextraType() == PEXTRA_FLOATFLT
3528 && (!params.pextraWidth().empty()
3529 || !params.pextraWidthp().empty())) {
3530 if (!params.pextraWidth().empty())
3531 os << "\\begin{floatingfigure}{"
3532 << params.pextraWidth() << "}\n";
3534 os << "\\begin{floatingfigure}{"
3535 << lyx::atoi(params.pextraWidthp()) / 100.0
3536 << "\\textwidth}\n";
3538 os << "\\begin{figure}";
3539 if (!bparams.float_placement.empty()) {
3540 os << '[' << bparams.float_placement << "]\n";
3546 case LyXParagraph::TAB:
3547 os << "\\begin{table}";
3548 if (!bparams.float_placement.empty()) {
3549 os << '[' << bparams.float_placement << "]\n";
3554 case LyXParagraph::WIDE_FIG:
3555 os << "\\begin{figure*}";
3556 if (!bparams.float_placement.empty()) {
3557 os << '[' << bparams.float_placement << "]\n";
3562 case LyXParagraph::WIDE_TAB:
3563 os << "\\begin{table*}";
3564 if (!bparams.float_placement.empty()) {
3565 os << '[' << bparams.float_placement << "]\n";
3570 case LyXParagraph::ALGORITHM:
3571 os << "\\begin{algorithm}\n";
3576 if (footnotekind != LyXParagraph::FOOTNOTE
3577 || !footer_in_body) {
3578 // Process text for all floats except footnotes in body
3580 LyXLayout const & style =
3582 .Style(bparams.textclass, par->layout);
3584 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3586 if (style.isEnvironment()
3587 || par->params.pextraType() == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3588 // Allows the use of minipages within float
3589 // environments. Shouldn't be circular because
3590 // we don't support footnotes inside
3591 // floats (yet). ARRae
3592 par = par->TeXEnvironment(buf, bparams, os,
3597 par = par->TeXOnePar(buf, bparams,
3598 os, texrow, moving_arg,
3603 if (par && !par->IsDummy() && par->params.depth() > params.depth()) {
3604 par = par->TeXDeeper(buf, bparams, os, texrow,
3608 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3610 // process footnotes > depth 0 or in environments separately
3611 // NOTE: Currently don't support footnotes within footnotes
3612 // even though that is possible using the \footnotemark
3613 std::ostringstream dummy;
3614 TexRow dummy_texrow;
3615 int dummy_count = 0;
3617 LyXLayout const & style =
3619 .Style(bparams.textclass, par->layout);
3621 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3623 if (style.isEnvironment()
3624 || par->params.pextraType() == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3625 // Allows the use of minipages within float
3626 // environments. Shouldn't be circular because
3627 // we don't support footnotes inside
3628 // floats (yet). ARRae
3629 par = par->TeXEnvironment(buf, bparams,
3631 dummy, dummy_texrow,
3634 par = par->TeXOnePar(buf, bparams,
3637 dummy, dummy_texrow,
3641 if (par && !par->IsDummy() && par->params.depth() > params.depth()) {
3642 par = par->TeXDeeper(buf, bparams,
3644 dummy, dummy_texrow,
3648 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3650 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3651 "Footnote in a Footnote -- not supported"
3656 switch (footnotekind) {
3657 case LyXParagraph::FOOTNOTE:
3658 if (footer_in_body) {
3659 // This helps tell which of the multiple
3660 // footnotetexts an error was in.
3662 foot_texrow.newline();
3667 case LyXParagraph::MARGIN:
3670 case LyXParagraph::FIG:
3671 if (params.pextraType() == PEXTRA_FLOATFLT
3672 && (!params.pextraWidth().empty()
3673 || !params.pextraWidthp().empty()))
3674 os << "\\end{floatingfigure}";
3676 os << "\\end{figure}";
3678 case LyXParagraph::TAB:
3679 os << "\\end{table}";
3681 case LyXParagraph::WIDE_FIG:
3682 os << "\\end{figure*}";
3684 case LyXParagraph::WIDE_TAB:
3685 os << "\\end{table*}";
3687 case LyXParagraph::ALGORITHM:
3688 os << "\\end{algorithm}";
3695 if (footnotekind != LyXParagraph::FOOTNOTE
3696 && footnotekind != LyXParagraph::MARGIN) {
3697 // we need to ensure that real floats like tables and figures
3698 // have their \end{} on a line of their own otherwise we can
3699 // get incorrect results when using the endfloat.sty package.
3704 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next_ << endl;
3709 bool LyXParagraph::IsDummy() const
3711 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous_
3712 && previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3716 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
3717 int type, string const & width,
3718 string const & widthp)
3720 params.pextraType(type);
3721 params.pextraWidth(width);
3722 params.pextraWidthp(widthp);
3724 if (textclasslist.Style(bparams.textclass,
3725 layout).isEnvironment()) {
3726 LyXParagraph * par = this;
3727 LyXParagraph * ppar = par;
3729 while (par && (par->layout == layout)
3730 && (par->params.depth() == params.depth())) {
3732 par = par->previous();
3735 par = par->FirstPhysicalPar();
3737 while (par && par->params.depth() > params.depth()) {
3738 par = par->previous();
3741 par = par->FirstPhysicalPar();
3746 while (par && (par->layout == layout)
3747 && (par->params.depth() == params.depth())) {
3748 par->params.pextraType(type);
3749 par->params.pextraWidth(width);
3750 par->params.pextraWidthp(widthp);
3752 par = par->NextAfterFootnote();
3756 if (par && (par->params.depth() > params.depth()))
3757 par->SetPExtraType(bparams,
3758 type, width, widthp);
3760 while (par && ((par->params.depth() > params.depth()) || par->IsDummy()))
3761 par = par->NextAfterFootnote();
3763 while (par && par->params.depth() > params.depth())
3771 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
3773 if (params.pextraType() == PEXTRA_NONE)
3776 params.pextraType(PEXTRA_NONE);
3777 params.pextraWidth(string());
3778 params.pextraWidthp(string());
3780 if (textclasslist.Style(bparams.textclass,
3781 layout).isEnvironment()) {
3782 LyXParagraph * par = this;
3783 LyXParagraph * ppar = par;
3785 while (par && (par->layout == layout)
3786 && (par->params.depth() == params.depth())) {
3788 par = par->previous();
3791 par = par->FirstPhysicalPar();
3793 while (par && par->params.depth() > params.depth()) {
3794 par = par->previous();
3797 par = par->FirstPhysicalPar();
3802 while (par && (par->layout == layout)
3803 && (par->params.depth() == params.depth())) {
3804 par->params.pextraType(PEXTRA_NONE);
3805 par->params.pextraWidth(string());
3806 par->params.pextraWidthp(string());
3808 par = par->NextAfterFootnote();
3812 if (par && (par->params.depth() > params.depth()))
3813 par->UnsetPExtraType(bparams);
3815 while (par && ((par->params.depth() > params.depth()) || par->IsDummy()))
3816 par = par->NextAfterFootnote();
3818 while (par && par->params.depth() > params.depth())
3826 bool LyXParagraph::IsHfill(size_type pos) const
3828 return IsHfillChar(GetChar(pos));
3832 bool LyXParagraph::IsInset(size_type pos) const
3834 return IsInsetChar(GetChar(pos));
3839 bool LyXParagraph::IsFloat(size_type pos) const
3841 return IsFloatChar(GetChar(pos));
3846 bool LyXParagraph::IsNewline(size_type pos) const
3848 return pos >= 0 && IsNewlineChar(GetChar(pos));
3852 bool LyXParagraph::IsSeparator(size_type pos) const
3854 return IsSeparatorChar(GetChar(pos));
3858 bool LyXParagraph::IsLineSeparator(size_type pos) const
3860 return IsLineSeparatorChar(GetChar(pos));
3864 bool LyXParagraph::IsKomma(size_type pos) const
3866 return IsKommaChar(GetChar(pos));
3870 /// Used by the spellchecker
3871 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
3873 value_type const c = GetChar(pos);
3874 if (IsLetterChar(c))
3876 // '\0' is not a letter, allthough every string contains "" (below)
3879 // We want to pass the ' and escape chars to ispell
3880 string const extra = lyxrc.isp_esc_chars + '\'';
3881 char ch[2] = { c, 0 };
3882 return contains(extra, ch);
3886 bool LyXParagraph::IsWord(size_type pos ) const
3888 return IsWordChar(GetChar(pos)) ;
3893 LyXParagraph::getParLanguage(BufferParams const & bparams) const
3897 return FirstPhysicalPar()->getParLanguage(bparams);
3901 return GetFirstFontSettings().language();
3903 return previous_->getParLanguage(bparams);
3905 return bparams.language;
3909 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
3911 return lyxrc.rtl_support
3912 && getParLanguage(bparams)->RightToLeft();
3916 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
3917 Language const * from, Language const * to)
3919 for (size_type i = 0; i < size(); ++i) {
3920 LyXFont font = GetFontSettings(bparams, i);
3921 if (font.language() == from) {
3922 font.setLanguage(to);
3929 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
3931 Language const * doc_language = bparams.language;
3932 for (FontList::const_iterator cit = fontlist.begin();
3933 cit != fontlist.end(); ++cit)
3934 if ((*cit).font().language() != doc_language)
3940 // Convert the paragraph to a string.
3941 // Used for building the table of contents
3942 string const LyXParagraph::String(Buffer const * buffer, bool label)
3944 BufferParams const & bparams = buffer->params;
3947 if (label && !IsDummy() && !params.labelString().empty())
3949 if (label && !params.labelString().empty())
3951 s += params.labelString() + ' ';
3952 string::size_type const len = s.size();
3954 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
3955 value_type c = GetChar(i);
3958 else if (c == META_INSET &&
3959 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
3960 std::ostringstream ost;
3961 GetInset(i)->Ascii(buffer, ost);
3962 s += subst(ost.str().c_str(),'\n',' ');
3967 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
3968 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
3969 s += NextAfterFootnote()->String(buffer, false);
3973 if (isRightToLeftPar(bparams))
3974 reverse(s.begin() + len,s.end());
3982 string const LyXParagraph::String(Buffer const * buffer,
3983 LyXParagraph::size_type beg,
3984 LyXParagraph::size_type end)
3989 if (beg == 0 && !IsDummy() && !params.labelString().empty())
3991 if (beg == 0 && !params.labelString().empty())
3993 s += params.labelString() + ' ';
3995 for (LyXParagraph::size_type i = beg; i < end; ++i) {
3996 value_type c = GetUChar(buffer->params, i);
3999 else if (c == META_INSET) {
4000 std::ostringstream ost;
4001 GetInset(i)->Ascii(buffer, ost);
4002 s += ost.str().c_str();
4010 void LyXParagraph::SetInsetOwner(Inset * i)
4013 for (InsetList::const_iterator cit = insetlist.begin();
4014 cit != insetlist.end(); ++cit) {
4016 (*cit).inset->setOwner(i);
4021 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4024 for (InsetList::const_iterator cit = insetlist.begin();
4025 cit != insetlist.end(); ++cit) {
4027 if ((*cit).inset->IsTextInset()) {
4028 static_cast<UpdatableInset *>
4029 ((*cit).inset)->deleteLyXText(bv);
4036 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4039 for (InsetList::const_iterator cit = insetlist.begin();
4040 cit != insetlist.end(); ++cit) {
4042 if ((*cit).inset->IsTextInset()) {
4043 static_cast<UpdatableInset *>
4044 ((*cit).inset)->resizeLyXText(bv);
4051 void LyXParagraph::fitToSize()
4053 TextContainer tmp(text.begin(), text.end());
4058 void LyXParagraph::setContentsFromPar(LyXParagraph * par)