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
62 LyXFont minibuffer_font;
63 Inset * minibuffer_inset;
68 extern BufferView * current_view;
70 // Initialization of the counter for the paragraph id's,
71 // declared in lyxparagraph.h
72 unsigned int LyXParagraph::paragraph_id = 0;
74 // Initialize static member.
75 ShareContainer<LyXFont> LyXParagraph::FontTable::container;
78 LyXParagraph::LyXParagraph()
80 text.reserve(500); // is this number too big?
81 for (int i = 0; i < 10; ++i) setCounter(i , 0);
87 footnoteflag = LyXParagraph::NO_FOOTNOTE;
88 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
93 bibkey = 0; // ale970302
98 // This konstruktor inserts the new paragraph in a list.
99 LyXParagraph::LyXParagraph(LyXParagraph * par)
104 for (int i = 0; i < 10; ++i) setCounter(i, 0);
107 // double linked list begin
110 next_->previous_ = this;
112 previous_->next_ = this;
115 footnoteflag = LyXParagraph::NO_FOOTNOTE;
116 footnotekind = LyXParagraph::FOOTNOTE;
119 id_ = paragraph_id++;
121 bibkey = 0; // ale970302
127 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
128 BufferParams const & bparams,
129 char footflag, char dth) const
132 if (footnoteflag != LyXParagraph::NO_FOOTNOTE ||
134 || 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] << " ";
215 if (params.pextraType() != PEXTRA_NONE) {
216 os << "\\pextra_type " << params.pextraType();
217 if (params.pextraType() == PEXTRA_MINIPAGE) {
218 os << " \\pextra_alignment "
219 << params.pextraAlignment();
220 if (params.pextraHfill())
221 os << " \\pextra_hfill "
222 << params.pextraHfill();
223 if (params.pextraStartMinipage())
224 os << " \\pextra_start_minipage "
225 << params.pextraStartMinipage();
227 if (!params.pextraWidth().empty()) {
228 os << " \\pextra_width "
229 << VSpace(params.pextraWidth()).asLyXCommand();
230 } else if (!params.pextraWidthp().empty()) {
231 os << " \\pextra_widthp "
232 << params.pextraWidthp();
239 // Dummy layout. This means that a footnote ended.
240 os << "\n\\end_float ";
241 footflag = LyXParagraph::NO_FOOTNOTE;
247 bibkey->Write(buf, os);
249 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
252 for (size_type i = 0; i < size(); ++i) {
258 // Write font changes
259 LyXFont font2 = GetFontSettings(bparams, i);
260 if (font2 != font1) {
261 font2.lyxWriteChanges(font1, os);
266 value_type const c = GetChar(i);
270 Inset const * inset = GetInset(i);
272 if (inset->DirectWrite()) {
273 // international char, let it write
274 // code directly so it's shorter in
276 inset->Write(buf, os);
278 os << "\n\\begin_inset ";
279 inset->Write(buf, os);
280 os << "\n\\end_inset \n\n";
286 os << "\n\\newline \n";
290 os << "\n\\hfill \n";
294 os << "\n\\backslash \n";
298 if (i + 1 < size() && GetChar(i + 1) == ' ') {
305 if ((column > 70 && c == ' ')
310 // this check is to amend a bug. LyX sometimes
311 // inserts '\0' this could cause problems.
315 lyxerr << "ERROR (LyXParagraph::writeFile):"
316 " NULL char in structure." << endl;
322 // now write the next paragraph
324 next_->writeFile(buf, os, bparams, footflag, dth);
328 void LyXParagraph::validate(LaTeXFeatures & features) const
330 BufferParams const & bparams = features.bufferParams();
333 // this will be useful later
334 LyXLayout const & layout =
335 textclasslist.Style(bparams.textclass,
340 if (params.lineTop() || params.lineBottom())
341 features.lyxline = true;
342 if (!params.spacing().isDefault())
343 features.setspace = true;
346 features.layout[GetLayout()] = true;
349 Language const * doc_language = bparams.language;
351 for (FontList::const_iterator cit = fontlist.begin();
352 cit != fontlist.end(); ++cit) {
353 if ((*cit).font().noun() == LyXFont::ON) {
354 lyxerr[Debug::LATEX] << "font.noun: "
355 << (*cit).font().noun()
357 features.noun = true;
358 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
359 << (*cit).font().stateText(0)
362 switch ((*cit).font().color()) {
364 case LColor::inherit:
368 features.color = true;
369 lyxerr[Debug::LATEX] << "Color enabled. Font: "
370 << (*cit).font().stateText(0)
374 Language const * language = (*cit).font().language();
375 if (language->babel() != doc_language->babel()) {
376 features.UsedLanguages.insert(language);
377 lyxerr[Debug::LATEX] << "Found language "
378 << language->babel() << endl;
383 for (InsetList::const_iterator cit = insetlist.begin();
384 cit != insetlist.end(); ++cit) {
386 (*cit).inset->Validate(features);
390 if (params.pextraType() == PEXTRA_INDENT)
391 features.LyXParagraphIndent = true;
392 if (params.pextraType() == PEXTRA_FLOATFLT)
393 features.floatflt = true;
396 if (layout.needprotect
397 && next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
398 features.NeedLyXFootnoteCode = true;
401 if (bparams.paragraph_separation == BufferParams::PARSEP_INDENT
402 && params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE)
403 features.NeedLyXMinipageIndent = true;
406 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
407 features.algorithm = true;
412 // First few functions needed for cut and paste and paragraph breaking.
413 void LyXParagraph::CopyIntoMinibuffer(Buffer const & buffer,
414 LyXParagraph::size_type pos) const
416 BufferParams bparams = buffer.params;
418 minibuffer_char = GetChar(pos);
419 minibuffer_font = GetFontSettings(bparams, pos);
420 minibuffer_inset = 0;
421 if (minibuffer_char == LyXParagraph::META_INSET) {
423 minibuffer_inset = GetInset(pos)->Clone(buffer);
425 minibuffer_inset = 0;
426 minibuffer_char = ' ';
427 // This reflects what GetInset() does (ARRae)
433 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
434 LyXParagraph::size_type pos)
436 minibuffer_char = GetChar(pos);
437 minibuffer_font = GetFontSettings(bparams, pos);
438 minibuffer_inset = 0;
439 if (minibuffer_char == LyXParagraph::META_INSET) {
441 minibuffer_inset = GetInset(pos);
442 // This is a little hack since I want exactly
443 // the inset, not just a clone. Otherwise
444 // the inset would be deleted when calling Erase(pos)
446 InsetTable search_elem(pos, 0);
447 InsetList::iterator it =
448 lower_bound(insetlist.begin(),
450 search_elem, matchIT());
451 if (it != insetlist.end() && (*it).pos == pos)
454 minibuffer_inset = 0;
455 minibuffer_char = ' ';
456 // This reflects what GetInset() does (ARRae)
461 // Erase(pos); now the caller is responsible for that.
465 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
467 if ((minibuffer_char == LyXParagraph::META_INSET) &&
468 !InsertInsetAllowed(minibuffer_inset))
470 if (minibuffer_char == LyXParagraph::META_INSET)
471 InsertInset(pos, minibuffer_inset, minibuffer_font);
473 InsertChar(pos, minibuffer_char, minibuffer_font);
481 void LyXParagraph::Clear()
490 // the destructor removes the new paragraph from the list
491 LyXParagraph::~LyXParagraph()
494 previous_->next_ = next_;
496 next_->previous_ = previous_;
498 for (InsetList::iterator it = insetlist.begin();
499 it != insetlist.end(); ++it) {
506 //lyxerr << "LyXParagraph::paragraph_id = "
507 // << LyXParagraph::paragraph_id << endl;
511 void LyXParagraph::Erase(LyXParagraph::size_type pos)
514 // > because last is the next unused position, and you can
515 // use it if you want
517 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
518 NextAfterFootnote()->Erase(pos - text.size() - 1);
520 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
521 "position does not exist." << endl;
525 Assert(pos < size());
528 if (pos < size()) { // last is free for insertation, but should be empty
530 // if it is an inset, delete the inset entry
531 if (text[pos] == LyXParagraph::META_INSET) {
533 InsetTable search_inset(pos, 0);
534 InsetList::iterator it =
535 lower_bound(insetlist.begin(),
537 search_inset, matchIT());
538 if (it != insetlist.end() && (*it).pos == pos) {
544 text.erase(text.begin() + pos);
546 // Erase entries in the tables.
547 FontTable search_font(pos, LyXFont());
549 FontList::iterator it =
550 lower_bound(fontlist.begin(),
552 search_font, matchFT());
553 if (it != fontlist.end() && (*it).pos() == pos &&
555 (it != fontlist.begin() && (*(it - 1)).pos() == pos - 1))) {
556 // If it is a multi-character font
557 // entry, we just make it smaller
558 // (see update below), otherwise we
560 unsigned int const i = it - fontlist.begin();
561 fontlist.erase(fontlist.begin() + i);
562 it = fontlist.begin() + i;
563 if (i > 0 && i < fontlist.size() &&
564 fontlist[i - 1].font() == fontlist[i].font()) {
565 fontlist.erase(fontlist.begin() + i - 1);
566 it = fontlist.begin() + i - 1;
570 // Update all other entries.
571 FontList::iterator fend = fontlist.end();
572 for (; it != fend; ++it)
573 (*it).pos((*it).pos() - 1);
575 // Update the inset table.
576 InsetTable search_inset(pos, 0);
577 InsetList::iterator lend = insetlist.end();
578 for (InsetList::iterator it =
579 upper_bound(insetlist.begin(),
581 search_inset, matchIT());
586 lyxerr << "ERROR (LyXParagraph::Erase): "
587 "can't erase non-existant char." << endl;
593 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
594 LyXParagraph::value_type c)
596 LyXFont const f(LyXFont::ALL_INHERIT);
597 InsertChar(pos, c, f);
601 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
602 LyXParagraph::value_type c,
603 LyXFont const & font)
606 // > because last is the next unused position, and you can
607 // use it if you want
610 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
611 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
614 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
615 "position does not exist." << endl;
619 Assert(pos <= size());
621 text.insert(text.begin() + pos, c);
623 // Update the font table.
624 FontTable search_font(pos, LyXFont());
625 for (FontList::iterator it = lower_bound(fontlist.begin(),
627 search_font, matchFT());
628 it != fontlist.end(); ++it)
629 (*it).pos((*it).pos() + 1);
631 // Update the inset table.
632 InsetTable search_inset(pos, 0);
633 for (InsetList::iterator it = lower_bound(insetlist.begin(),
635 search_inset, matchIT());
636 it != insetlist.end(); ++it)
643 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
646 LyXFont const f(LyXFont::ALL_INHERIT);
647 InsertInset(pos, inset, f);
651 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
652 Inset * inset, LyXFont const & font)
657 // > because last is the next unused position, and you can
658 // use it if you want
661 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
663 ->InsertInset(pos - text.size() - 1,
666 lyxerr << "ERROR (LyXParagraph::InsertInset): "
667 "position does not exist: " << pos << endl;
671 Assert(pos <= size());
674 InsertChar(pos, META_INSET, font);
675 Assert(text[pos] == META_INSET);
677 // Add a new entry in the inset table.
678 InsetTable search_inset(pos, 0);
679 InsetList::iterator it = lower_bound(insetlist.begin(),
681 search_inset, matchIT());
682 if (it != insetlist.end() && (*it).pos == pos)
683 lyxerr << "ERROR (LyXParagraph::InsertInset): "
684 "there is an inset in position: " << pos << endl;
686 insetlist.insert(it, InsetTable(pos, inset));
688 inset->setOwner(inset_owner);
692 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
694 //lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
697 return inset_owner->InsertInsetAllowed(inset);
702 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
707 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
708 return NextAfterFootnote()
709 ->GetInset(pos - text.size() - 1);
711 lyxerr << "ERROR (LyXParagraph::GetInset): "
712 "position does not exist: "
718 Assert(pos < size());
721 InsetTable search_inset(pos, 0);
722 InsetList::iterator it = lower_bound(insetlist.begin(),
724 search_inset, matchIT());
725 if (it != insetlist.end() && (*it).pos == pos)
728 lyxerr << "ERROR (LyXParagraph::GetInset): "
729 "Inset does not exist: " << pos << endl;
732 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
733 // Did this commenting out introduce a bug? So far I have not
734 // see any, please enlighten me. (Lgb)
735 // My guess is that since the inset does not exist, we might
736 // as well replace it with a space to prevent craches. (Asger)
741 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
746 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
747 return NextAfterFootnote()
748 ->GetInset(pos - text.size() - 1);
750 lyxerr << "ERROR (LyXParagraph::GetInset): "
751 "position does not exist: "
757 Assert(pos < size());
760 InsetTable search_inset(pos, 0);
761 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
763 search_inset, matchIT());
764 if (cit != insetlist.end() && (*cit).pos == pos)
767 lyxerr << "ERROR (LyXParagraph::GetInset): "
768 "Inset does not exist: " << pos << endl;
770 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
771 // Did this commenting out introduce a bug? So far I have not
772 // see any, please enlighten me. (Lgb)
773 // My guess is that since the inset does not exist, we might
774 // as well replace it with a space to prevent craches. (Asger)
779 // Gets uninstantiated font setting at position.
780 // Optimized after profiling. (Asger)
781 LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
782 LyXParagraph::size_type pos) const
785 Assert(pos <= size());
790 FontTable search_font(pos, LyXFont());
791 FontList::const_iterator cit = lower_bound(fontlist.begin(),
793 search_font, matchFT());
794 if (cit != fontlist.end())
795 return (*cit).font();
800 // > because last is the next unused position, and you can
801 // use it if you want
802 else if (pos > size()) {
804 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
805 return NextAfterFootnote()
806 ->GetFontSettings(bparams,
807 pos - text.size() - 1);
809 // Why is it an error to ask for the font of a
810 // position that does not exist? Would it be
811 // enough for this to be enabled on debug?
812 // We want strict error checking, but it's ok to only
813 // have it when debugging. (Asger)
814 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
815 "position does not exist. "
816 << pos << " (" << static_cast<int>(pos)
818 } else if (pos > 0) {
819 return GetFontSettings(bparams, pos - 1);
822 if (pos == size() && size())
823 return GetFontSettings(bparams, pos - 1);
827 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
829 //return LyXFont(LyXFont::ALL_INHERIT);
833 // Gets uninstantiated font setting at position 0
834 LyXFont const LyXParagraph::GetFirstFontSettings() const
837 if (!fontlist.empty())
838 return fontlist[0].font();
842 else if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
843 return NextAfterFootnote()->GetFirstFontSettings();
845 return LyXFont(LyXFont::ALL_INHERIT);
849 // Gets the fully instantiated font at a given position in a paragraph
850 // This is basically the same function as LyXText::GetFont() in text2.C.
851 // The difference is that this one is used for generating the LaTeX file,
852 // and thus cosmetic "improvements" are disallowed: This has to deliver
853 // the true picture of the buffer. (Asger)
854 // If position is -1, we get the layout font of the paragraph.
855 // If position is -2, we get the font of the manual label of the paragraph.
856 LyXFont const LyXParagraph::getFont(BufferParams const & bparams,
857 LyXParagraph::size_type pos) const
860 LyXLayout const & layout =
861 textclasslist.Style(bparams.textclass,
863 LyXParagraph::size_type main_body = 0;
864 if (layout.labeltype == LABEL_MANUAL)
865 main_body = BeginningOfMainBody();
870 layoutfont = layout.labelfont;
872 layoutfont = layout.font;
873 tmpfont = GetFontSettings(bparams, pos);
874 tmpfont.realize(layoutfont);
876 // process layoutfont for pos == -1 and labelfont for pos < -1
878 tmpfont = layout.font;
880 tmpfont = layout.labelfont;
881 tmpfont.setLanguage(getParLanguage(bparams));
884 // check for environment font information
885 char par_depth = GetDepth();
886 LyXParagraph const * par = this;
887 while (par && par_depth && !tmpfont.resolved()) {
888 par = par->DepthHook(par_depth - 1);
890 tmpfont.realize(textclasslist.
891 Style(bparams.textclass,
892 par->GetLayout()).font);
893 par_depth = par->GetDepth();
897 tmpfont.realize(textclasslist
898 .TextClass(bparams.textclass)
904 /// Returns the height of the highest font in range
906 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
907 LyXParagraph::size_type endpos) const
909 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
910 if (fontlist.empty())
913 FontTable end_search(endpos, LyXFont());
914 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
916 end_search, matchFT());
917 if (end_it != fontlist.end())
920 FontTable start_search(startpos, LyXFont());
921 for (FontList::const_iterator cit =
922 lower_bound(fontlist.begin(),
924 start_search, matchFT());
925 cit != end_it; ++cit) {
926 LyXFont::FONT_SIZE size = (*cit).font().size();
927 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
934 LyXParagraph::value_type
935 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
940 Assert(pos <= size());
941 if (!size() || pos == size()) return '\0';
952 // > because last is the next unused position, and you can
953 // use it if you want
954 else if (pos > size()) {
955 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
956 return NextAfterFootnote()
957 ->GetChar(pos - text.size() - 1);
960 lyxerr << "ERROR (LyXParagraph::GetChar const): "
961 "position does not exist."
962 << pos << " (" << static_cast<int>(pos)
968 // We should have a footnote environment.
969 if (!next_ || next_->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
970 // Notice that LyX does request the
971 // last char from time to time. (Asger)
972 //lyxerr << "ERROR (LyXParagraph::GetChar): "
973 // "expected footnote." << endl;
976 switch (next_->footnotekind) {
977 case LyXParagraph::FOOTNOTE:
978 return LyXParagraph::META_FOOTNOTE;
979 case LyXParagraph::MARGIN:
980 return LyXParagraph::META_MARGIN;
981 case LyXParagraph::FIG:
982 case LyXParagraph::WIDE_FIG:
983 return LyXParagraph::META_FIG;
984 case LyXParagraph::TAB:
985 case LyXParagraph::WIDE_TAB:
986 return LyXParagraph::META_TAB;
987 case LyXParagraph::ALGORITHM:
988 return LyXParagraph::META_ALGORITHM;
990 return '\0'; // to shut up gcc
996 LyXParagraph::value_type
997 LyXParagraph::GetUChar(BufferParams const & bparams,
998 LyXParagraph::size_type pos) const
1000 value_type c = GetChar(pos);
1001 if (!lyxrc.rtl_support)
1031 if (uc != c && GetFontSettings(bparams, pos).isRightToLeft())
1037 // return an string of the current word, and the end of the word in lastpos.
1038 string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1040 Assert(lastpos >= 0);
1042 // the current word is defined as starting at the first character
1043 // from the immediate left of lastpospos which meets the definition
1044 // of IsLetter(), continuing to the last character to the right
1045 // of this meeting IsLetter.
1051 // move back until we have a letter
1053 //there's no real reason to have firstpos & lastpos as
1054 //separate variables as this is written, but maybe someon
1055 // will want to return firstpos in the future.
1057 //since someone might have typed a punctuation first
1058 int firstpos = lastpos;
1060 while ((firstpos >= 0) && !IsLetter(firstpos))
1063 // now find the beginning by looking for a nonletter
1065 while ((firstpos>= 0) && IsLetter(firstpos))
1068 // the above is now pointing to the preceeding non-letter
1072 // so copy characters into theword until we get a nonletter
1073 // note that this can easily exceed lastpos, wich means
1074 // that if used in the middle of a word, the whole word
1077 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1085 LyXParagraph::size_type LyXParagraph::Last() const
1087 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1088 return text.size() + NextAfterFootnote()->Last() + 1;
1089 // the 1 is the symbol
1098 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1100 // > because last is the next unused position, and you can
1101 // use it if you want
1104 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1105 return NextAfterFootnote()
1106 ->ParFromPos(pos - text.size() - 1);
1108 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1109 "position does not exist." << endl;
1118 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1120 // > because last is the next unused position, and you can
1121 // use it if you want
1124 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1125 return NextAfterFootnote()
1126 ->PositionInParFromPos(pos - text.size() - 1);
1129 "ERROR (LyXParagraph::PositionInParFromPos): "
1130 "position does not exist." << endl;
1139 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1140 LyXFont const & font)
1143 // > because last is the next unused position, and you can
1144 // use it if you want
1147 next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1148 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1151 lyxerr << "ERROR (LyXParagraph::SetFont): "
1152 "position does not exist." << endl;
1157 Assert(pos <= size());
1160 // First, reduce font against layout/label font
1161 // Update: The SetCharFont() routine in text2.C already
1162 // reduces font, so we don't need to do that here. (Asger)
1163 // No need to simplify this because it will disappear
1164 // in a new kernel. (Asger)
1165 // Next search font table
1167 FontTable search_font(pos, LyXFont());
1168 FontList::iterator it = lower_bound(fontlist.begin(),
1170 search_font, matchFT());
1171 unsigned int i = it - fontlist.begin();
1172 bool notfound = it == fontlist.end();
1174 if (!notfound && fontlist[i].font() == font)
1177 bool begin = pos == 0 || notfound ||
1178 (i > 0 && fontlist[i-1].pos() == pos - 1);
1179 // Is position pos is a beginning of a font block?
1180 bool end = !notfound && fontlist[i].pos() == pos;
1181 // Is position pos is the end of a font block?
1182 if (begin && end) { // A single char block
1183 if (i + 1 < fontlist.size() &&
1184 fontlist[i + 1].font() == font) {
1185 // Merge the singleton block with the next block
1186 fontlist.erase(fontlist.begin() + i);
1187 if (i > 0 && fontlist[i - 1].font() == font)
1188 fontlist.erase(fontlist.begin() + i-1);
1189 } else if (i > 0 && fontlist[i - 1].font() == font) {
1190 // Merge the singleton block with the previous block
1191 fontlist[i - 1].pos(pos);
1192 fontlist.erase(fontlist.begin() + i);
1194 fontlist[i].font(font);
1196 if (i > 0 && fontlist[i - 1].font() == font)
1197 fontlist[i - 1].pos(pos);
1199 fontlist.insert(fontlist.begin() + i,
1200 FontTable(pos, font));
1202 fontlist[i].pos(pos - 1);
1203 if (!(i + 1 < fontlist.size() &&
1204 fontlist[i + 1].font() == font))
1205 fontlist.insert(fontlist.begin() + i + 1,
1206 FontTable(pos, font));
1207 } else { // The general case. The block is splitted into 3 blocks
1208 fontlist.insert(fontlist.begin() + i,
1209 FontTable(pos - 1, fontlist[i].font()));
1210 fontlist.insert(fontlist.begin() + i + 1,
1211 FontTable(pos, font));
1217 void LyXParagraph::next(LyXParagraph * p)
1223 // This function is able to hide closed footnotes.
1224 LyXParagraph * LyXParagraph::next()
1227 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1228 LyXParagraph * tmp = next_;
1230 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1232 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1233 return tmp->next(); /* there can be more than one
1234 footnote in a logical
1237 return next_; // This should never happen!
1244 LyXParagraph const * LyXParagraph::next() const
1247 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1248 LyXParagraph * tmp = next_;
1250 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1252 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1253 return tmp->next(); /* there can be more than one
1254 footnote in a logical
1257 return next_; // This should never happen!
1265 LyXParagraph * LyXParagraph::NextAfterFootnote()
1267 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1268 LyXParagraph * tmp = next_;
1269 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1271 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1272 return tmp; /* there can be more than one footnote
1273 in a logical paragraph */
1275 return next_; // This should never happen!
1283 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1285 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1286 LyXParagraph * tmp = next_;
1287 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1289 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1290 return tmp; /* there can be more than one footnote
1291 in a logical paragraph */
1293 return next_; // This should never happen!
1301 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1304 if (previous_ && previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1306 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1307 tmp = tmp->previous_;
1308 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1309 return tmp; /* there can be more than one footnote
1310 in a logical paragraph */
1312 return previous_; // This should never happen!
1320 LyXParagraph * LyXParagraph::LastPhysicalPar()
1322 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1325 LyXParagraph * tmp = this;
1327 && tmp->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1328 tmp = tmp->NextAfterFootnote();
1336 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1338 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1341 LyXParagraph const * tmp = this;
1343 && tmp->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1344 tmp = tmp->NextAfterFootnote();
1352 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1356 LyXParagraph * tmppar = this;
1360 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1361 tmppar = tmppar->previous_;
1372 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1376 LyXParagraph const * tmppar = this;
1380 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1381 tmppar = tmppar->previous_;
1391 void LyXParagraph::previous(LyXParagraph * p)
1397 // This function is able to hide closed footnotes.
1398 LyXParagraph * LyXParagraph::previous()
1401 LyXParagraph * tmp = previous_;
1406 && tmp->previous_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1407 tmp = tmp->previous_;
1409 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1410 tmp = tmp->previous_;
1411 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1412 return tmp->next_->previous();
1422 // This function is able to hide closed footnotes.
1423 LyXParagraph const * LyXParagraph::previous() const
1426 LyXParagraph * tmp = previous_;
1430 && tmp->previous_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1431 tmp = tmp->previous_;
1433 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1434 tmp = tmp->previous_;
1435 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1436 return tmp->next_->previous();
1446 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1447 LyXParagraph::size_type pos,
1452 // create a new paragraph
1455 size_type pos_first;
1456 LyXParagraph * par = ParFromPos(pos);
1457 LyXParagraph * firstpar = FirstPhysicalPar();
1459 LyXParagraph * tmp = new LyXParagraph(par);
1461 //LyXParagraph * par = this;
1462 //LyXParagraph * firstpar = this;
1463 LyXParagraph * tmp = new LyXParagraph(this);
1467 tmp->footnoteflag = footnoteflag;
1468 tmp->footnotekind = footnotekind;
1470 // this is an idea for a more userfriendly layout handling, I will
1471 // see what the users say
1474 // layout stays the same with latex-environments
1476 tmp->SetOnlyLayout(bparams, firstpar->layout);
1477 tmp->SetLabelWidthString(firstpar->params.labelWidthString());
1480 // layout stays the same with latex-environments
1482 tmp->SetOnlyLayout(bparams, layout);
1483 tmp->SetLabelWidthString(params.labelWidthString());
1487 if (Last() > pos || !Last() || flag == 2) {
1488 tmp->SetOnlyLayout(bparams, firstpar->layout);
1489 tmp->params.align(firstpar->params.align());
1490 tmp->SetLabelWidthString(firstpar->params.labelWidthString());
1492 tmp->params.lineBottom(firstpar->params.lineBottom());
1493 firstpar->params.lineBottom(false);
1494 tmp->params.pagebreakBottom(firstpar->params.pagebreakBottom());
1495 firstpar->params.pagebreakBottom(false);
1496 tmp->params.spaceBottom(firstpar->params.spaceBottom());
1497 firstpar->params.spaceBottom(VSpace(VSpace::NONE));
1499 tmp->params.depth(firstpar->params.depth());
1500 tmp->params.noindent(firstpar->params.noindent());
1502 if (size() > pos || !size() || flag == 2) {
1503 tmp->SetOnlyLayout(bparams, layout);
1504 tmp->params.align(params.align());
1505 tmp->SetLabelWidthString(params.labelWidthString());
1507 tmp->params.lineBottom(params.lineBottom());
1508 params.lineBottom(false);
1509 tmp->params.pagebreakBottom(params.pagebreakBottom());
1510 params.pagebreakBottom(false);
1511 tmp->params.spaceBottom(params.spaceBottom());
1512 params.spaceBottom(VSpace(VSpace::NONE));
1514 tmp->params.depth(params.depth());
1515 tmp->params.noindent(params.noindent());
1517 // copy everything behind the break-position
1518 // to the new paragraph
1521 while (ParFromPos(pos_first) != par)
1523 pos_end = pos_first + par->text.size() - 1;
1526 for (i = j = pos; i <= pos_end; ++i) {
1527 par->CutIntoMinibuffer(bparams, i - pos_first);
1528 if (tmp->InsertFromMinibuffer(j - pos))
1534 for (i = pos_end; i >= pos; --i)
1535 par->Erase(i - pos_first);
1539 size_type pos_end = text.size() - 1;
1541 for (i = j = pos; i <= pos_end; ++i) {
1542 CutIntoMinibuffer(bparams, i);
1543 if (tmp->InsertFromMinibuffer(j - pos))
1547 for (i = pos_end; i >= pos; --i)
1555 // just an idea of me
1557 tmp->params.lineTop(firstpar->params.lineTop());
1558 tmp->params.pagebreakTop(firstpar->params.pagebreakTop());
1559 tmp->params.spaceTop(firstpar->params.spaceTop());
1560 tmp->bibkey = firstpar->bibkey;
1562 // layout stays the same with latex-environments
1564 firstpar->SetOnlyLayout(bparams, tmp->layout);
1565 firstpar->SetLabelWidthString(tmp->params.labelWidthString());
1566 firstpar->params.depth(tmp->params.depth());
1570 // just an idea of me
1572 tmp->params.lineTop(params.lineTop());
1573 tmp->params.pagebreakTop(params.pagebreakTop());
1574 tmp->params.spaceTop(params.spaceTop());
1575 tmp->bibkey = bibkey;
1577 // layout stays the same with latex-environments
1579 SetOnlyLayout(bparams, tmp->layout);
1580 SetLabelWidthString(tmp->params.labelWidthString());
1581 params.depth(tmp->params.depth());
1588 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1591 par = par->FirstPhysicalPar();
1592 footnoteflag = par->footnoteflag;
1593 footnotekind = par->footnotekind;
1595 layout = par->layout;
1596 params.makeSame(par->params);
1598 // This can be changed after NEW_INSETS is in effect. (Lgb)
1599 SetLabelWidthString(par->params.labelWidthString());
1604 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1606 LyXParagraph * tmppar = this;
1609 && tmppar->previous_->footnoteflag ==
1610 LyXParagraph::CLOSED_FOOTNOTE)
1611 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1612 tmppar = tmppar->previous_;
1615 return this; // This should never happen!
1622 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1624 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1634 && (IsNewline(0) || IsLineSeparator(0))){
1645 LyXParagraph * LyXParagraph::Clone() const
1647 // create a new paragraph
1648 LyXParagraph * result = new LyXParagraph;
1650 result->MakeSameLayout(this);
1652 // this is because of the dummy layout of the paragraphs that
1654 result->layout = layout;
1656 result->inset_owner = inset_owner;
1660 result->bibkey = static_cast<InsetBibKey *>
1661 (bibkey->Clone(*current_view->buffer()));
1665 // copy everything behind the break-position to the new paragraph
1667 result->text = text;
1668 result->fontlist = fontlist;
1669 result->insetlist = insetlist;
1670 for (InsetList::iterator it = result->insetlist.begin();
1671 it != result->insetlist.end(); ++it)
1672 (*it).inset = (*it).inset->Clone(*current_view->buffer());
1677 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1680 par = par->FirstPhysicalPar();
1685 par->footnoteflag == footnoteflag &&
1686 par->footnotekind == footnotekind &&
1688 par->layout == layout &&
1689 params.sameLayout(par->params);
1693 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1694 LyXParagraph::size_type pos)
1697 // create a new paragraph
1698 LyXParagraph * par = ParFromPos(pos);
1700 LyXParagraph * tmp = new LyXParagraph(par);
1702 tmp->MakeSameLayout(par);
1704 // When can pos < Last()?
1705 // I guess pos == Last() is possible.
1707 // copy everything behind the break-position to the new
1709 size_type pos_first = 0;
1710 while (ParFromPos(pos_first) != par)
1712 size_type pos_end = pos_first + par->text.size() - 1;
1715 for (i = j = pos; i <= pos_end; ++i) {
1716 par->CutIntoMinibuffer(bparams, i - pos_first);
1717 if (tmp->InsertFromMinibuffer(j - pos))
1723 for (size_type i = pos_end; i >= pos; --i)
1724 par->Erase(i - pos_first);
1729 // create a new paragraph
1730 LyXParagraph * tmp = new LyXParagraph(this);
1731 tmp->MakeSameLayout(this);
1733 // When can pos > Last()?
1734 // I guess pos == Last() is possible.
1736 // copy everything behind the break-position to the new
1738 size_type pos_end = text.size() - 1;
1741 for (i = j = pos; i <= pos_end; ++i) {
1742 CutIntoMinibuffer(bparams, i);
1743 if (tmp->InsertFromMinibuffer(j - pos))
1749 for (size_type i = pos_end; i >= pos; --i)
1758 // Be carefull, this does not make any check at all.
1759 // This method has wrong name, it combined this par with the next par.
1760 // In that sense it is the reverse of break paragraph. (Lgb)
1761 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1763 // copy the next paragraph to this one
1764 LyXParagraph * the_next = next();
1766 // first the DTP-stuff
1768 LyXParagraph * firstpar = FirstPhysicalPar();
1769 firstpar->params.lineBottom(the_next->params.lineBottom());
1770 firstpar->params.spaceBottom(the_next->params.spaceBottom());
1771 firstpar->params.pagebreakBottom(the_next->params.pagebreakBottom());
1773 size_type pos_end = the_next->text.size() - 1;
1774 size_type pos_insert = Last();
1776 params.lineBottom(the_next->params.lineBottom());
1777 params.spaceBottom(the_next->params.spaceBottom());
1778 params.pagebreakBottom(the_next->params.pagebreakBottom());
1780 size_type pos_end = the_next->text.size() - 1;
1781 size_type pos_insert = size();
1784 // ok, now copy the paragraph
1786 for (i = j = 0; i <= pos_end; ++i) {
1787 the_next->CutIntoMinibuffer(bparams, i);
1788 if (InsertFromMinibuffer(pos_insert + j))
1792 // delete the next paragraph
1793 LyXParagraph * ppar = the_next->previous_;
1794 LyXParagraph * npar = the_next->next_;
1801 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1803 LyXParagraph * par = ParFromPos(pos);
1805 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1806 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1812 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1814 LyXParagraph * par = ParFromPos(pos);
1816 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1817 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1824 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1826 LyXParagraph const * par = this;
1827 int par_depth = GetDepth();
1829 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1830 int const endlabeltype =
1831 textclasslist.Style(bparams.textclass,
1832 layout).endlabeltype;
1833 if (endlabeltype != END_LABEL_NO_LABEL) {
1834 LyXParagraph const * last = this;
1836 if (footnoteflag == NO_FOOTNOTE)
1837 last = LastPhysicalPar();
1838 else if (next_->footnoteflag == NO_FOOTNOTE)
1839 return endlabeltype;
1844 if (!last || !last->next_)
1845 return endlabeltype;
1847 int next_depth = last->next_->GetDepth();
1848 if (par_depth > next_depth ||
1849 (par_depth == next_depth && layout != last->next_->GetLayout() ))
1850 return endlabeltype;
1855 par = par->DepthHook(par_depth - 1);
1857 par_depth = par->GetDepth();
1859 return END_LABEL_NO_LABEL;
1863 LyXTextClass::size_type LyXParagraph::GetLayout() const
1866 return FirstPhysicalPar()->layout;
1873 char LyXParagraph::GetDepth() const
1876 return FirstPhysicalPar()->params.depth();
1878 return params.depth();
1883 char LyXParagraph::GetAlign() const
1886 return FirstPhysicalPar()->params.align();
1888 return params.align();
1893 string const & LyXParagraph::GetLabelstring() const
1896 return FirstPhysicalPar()->params.labelString();
1898 return params.labelString();
1903 int LyXParagraph::GetFirstCounter(int i) const
1906 return FirstPhysicalPar()->counter_[i];
1913 // the next two functions are for the manual labels
1914 string const LyXParagraph::GetLabelWidthString() const
1917 if (!FirstPhysicalPar()->params.labelWidthString().empty())
1918 return FirstPhysicalPar()->params.labelWidthString();
1920 if (!params.labelWidthString().empty())
1921 return params.labelWidthString();
1924 return _("Senseless with this layout!");
1928 void LyXParagraph::SetLabelWidthString(string const & s)
1931 LyXParagraph * par = FirstPhysicalPar();
1933 par->params.labelWidthString(s);
1935 params.labelWidthString(s);
1940 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1941 LyXTextClass::size_type new_layout)
1944 LyXParagraph * par = FirstPhysicalPar();
1946 LyXParagraph * par = this;
1948 LyXParagraph * ppar = 0;
1949 LyXParagraph * npar = 0;
1951 par->layout = new_layout;
1954 if (par->params.pextraType() == PEXTRA_NONE) {
1956 if (par->previous()) {
1958 ppar = par->previous()->FirstPhysicalPar();
1960 ppar = par->previous();
1964 && (ppar->params.depth() > par->params.depth()))
1966 ppar = ppar->previous()->FirstPhysicalPar();
1968 ppar = ppar->previous();
1973 npar = par->next()->NextAfterFootnote();
1979 && (npar->params.depth() > par->params.depth()))
1981 npar = npar->next()->NextAfterFootnote();
1983 npar = npar->next();
1987 if (ppar && (ppar->params.pextraType() != PEXTRA_NONE)) {
1988 string p1 = ppar->params.pextraWidth();
1989 string p2 = ppar->params.pextraWidthp();
1990 ppar->SetPExtraType(bparams,
1991 ppar->params.pextraType(),
1994 if ((par->params.pextraType() == PEXTRA_NONE) &&
1995 npar && (npar->params.pextraType() != PEXTRA_NONE)) {
1996 string const p1 = npar->params.pextraWidth();
1997 string const p2 = npar->params.pextraWidthp();
1998 npar->SetPExtraType(bparams, npar->params.pextraType(),
2006 void LyXParagraph::SetLayout(BufferParams const & bparams,
2007 LyXTextClass::size_type new_layout)
2011 * par = FirstPhysicalPar(),
2018 par->layout = new_layout;
2019 par->params.labelWidthString(string());
2020 par->params.align(LYX_ALIGN_LAYOUT);
2021 par->params.spaceTop(VSpace(VSpace::NONE));
2022 par->params.spaceBottom(VSpace(VSpace::NONE));
2023 par->params.spacing(Spacing(Spacing::Default));
2026 if (par->params.pextraType() == PEXTRA_NONE) {
2028 if (par->previous()) {
2030 ppar = par->previous()->FirstPhysicalPar();
2032 ppar = par->previous();
2036 && (ppar->params.depth() > par->params.depth()))
2038 ppar = ppar->previous()->FirstPhysicalPar();
2040 ppar = ppar->previous();
2045 npar = par->next()->NextAfterFootnote();
2051 && (npar->params.depth() > par->params.depth()))
2053 npar = npar->next()->NextAfterFootnote();
2055 npar = npar->next();
2059 if (ppar && (ppar->params.pextraType() != PEXTRA_NONE)) {
2060 string const p1 = ppar->params.pextraWidth();
2061 string const p2 = ppar->params.pextraWidthp();
2062 ppar->SetPExtraType(bparams, ppar->params.pextraType(),
2065 if ((par->params.pextraType() == PEXTRA_NONE) &&
2066 npar && (npar->params.pextraType() != PEXTRA_NONE)) {
2067 string const p1 = npar->params.pextraWidth();
2068 string const p2 = npar->params.pextraWidthp();
2069 npar->SetPExtraType(bparams, npar->params.pextraType(),
2077 // if the layout of a paragraph contains a manual label, the beginning of the
2078 // main body is the beginning of the second word. This is what the par-
2079 // function returns. If the layout does not contain a label, the main
2080 // body always starts with position 0. This differentiation is necessary,
2081 // because there cannot be a newline or a blank <= the beginning of the
2082 // main body in TeX.
2084 int LyXParagraph::BeginningOfMainBody() const
2087 if (FirstPhysicalPar() != this)
2090 // Unroll the first two cycles of the loop
2091 // and remember the previous character to
2092 // remove unnecessary GetChar() calls
2095 && GetChar(i) != LyXParagraph::META_NEWLINE
2098 char previous_char = 0;
2101 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2102 // Yes, this ^ is supposed to be "= " not "=="
2105 && previous_char != ' '
2106 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2108 previous_char = temp;
2114 if (i == 0 && i == size() &&
2115 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2116 && next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2117 ++i; /* the cursor should not jump
2118 * to the main body if there
2125 LyXParagraph * LyXParagraph::DepthHook(int deth)
2127 LyXParagraph * newpar = this;
2133 newpar = newpar->FirstPhysicalPar()->previous();
2135 newpar = newpar->previous();
2137 } while (newpar && newpar->GetDepth() > deth
2139 && newpar->footnoteflag == footnoteflag
2144 if (previous() || GetDepth())
2145 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2150 return newpar->FirstPhysicalPar();
2157 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2159 LyXParagraph const * newpar = this;
2165 newpar = newpar->FirstPhysicalPar()->previous();
2167 newpar = newpar->previous();
2169 } while (newpar && newpar->GetDepth() > deth
2171 && newpar->footnoteflag == footnoteflag
2176 if (previous() || GetDepth())
2177 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2182 return newpar->FirstPhysicalPar();
2189 int LyXParagraph::AutoDeleteInsets()
2192 InsetList::size_type index = 0;
2193 while (index < insetlist.size()) {
2194 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2195 Erase(insetlist[index].pos);
2196 // Erase() calls to insetlist.erase(&insetlist[index])
2197 // so index shouldn't be increased.
2206 LyXParagraph::inset_iterator
2207 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2209 InsetTable search_inset(pos, 0);
2210 InsetList::iterator it = lower_bound(insetlist.begin(),
2212 search_inset, matchIT());
2213 return inset_iterator(it);
2217 // returns -1 if inset not found
2218 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2221 for (InsetList::const_iterator cit = insetlist.begin();
2222 cit != insetlist.end(); ++cit) {
2223 if ((*cit).inset == inset) {
2227 if (inset == bibkey)
2231 // Think about footnotes.
2232 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2233 && next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2235 NextAfterFootnote()->GetPositionOfInset(inset);
2237 return text.size() + 1 + further;
2244 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2245 BufferParams const & bparams,
2246 ostream & os, TexRow & texrow,
2251 TexRow & foot_texrow,
2256 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2257 LyXLayout const & style =
2258 textclasslist.Style(bparams.textclass,
2261 bool further_blank_line = false;
2264 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2267 if (params.startOfAppendix()) {
2268 os << "\\appendix\n";
2272 if (!params.spacing().isDefault()
2273 && (!previous() || !previous()->HasSameLayout(this))) {
2274 os << params.spacing().writeEnvirBegin() << "\n";
2278 if (tex_code_break_column && style.isCommand()){
2283 if (params.pagebreakTop()) {
2285 further_blank_line = true;
2287 if (params.spaceTop().kind() != VSpace::NONE) {
2288 os << params.spaceTop().asLatexCommand(bparams);
2289 further_blank_line = true;
2292 if (params.lineTop()) {
2293 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2294 << "\\vspace{-1\\parskip}";
2295 further_blank_line = true;
2298 if (further_blank_line){
2303 Language const * language = getParLanguage(bparams);
2304 Language const * doc_language = bparams.language;
2305 Language const * previous_language = previous_
2306 ? previous_->getParLanguage(bparams) : doc_language;
2307 if (language->babel() != doc_language->babel() &&
2308 language->babel() != previous_language->babel()) {
2309 os << subst(lyxrc.language_command_begin, "$$lang",
2315 if (bparams.inputenc == "auto" &&
2316 language->encoding() != previous_language->encoding()) {
2317 os << "\\inputencoding{"
2318 << language->encoding()->LatexName()
2323 switch (style.latextype) {
2326 << style.latexname()
2327 << style.latexparam();
2329 case LATEX_ITEM_ENVIRONMENT:
2331 bibkey->Latex(buf, os, false, false);
2335 case LATEX_LIST_ENVIRONMENT:
2342 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2344 LyXParagraph * par = next_;
2346 // Spit out footnotes
2347 if (lyxrc.rtl_support) {
2348 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
2349 && next_->footnoteflag != footnoteflag) {
2350 LyXParagraph * p = 0;
2351 bool is_rtl = (size() > 0)
2352 ? GetFontSettings(bparams,
2353 size()-1).isRightToLeft()
2354 : language->RightToLeft();
2355 if ((p = NextAfterFootnote()) != 0 &&
2357 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2358 is_rtl = getParLanguage(bparams)->RightToLeft();
2359 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2360 && par->footnoteflag != footnoteflag) {
2361 par = par->TeXFootnote(buf, bparams,
2363 foot_texrow, foot_count,
2365 par->SimpleTeXOnePar(buf, bparams,
2366 os, texrow, moving_arg);
2367 is_rtl = (par->size() > 0)
2368 ? par->GetFontSettings(bparams,
2369 par->size()-1).isRightToLeft()
2370 : language->RightToLeft();
2372 par->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2373 (p = par->NextAfterFootnote()) != 0 &&
2375 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2376 is_rtl = language->RightToLeft();
2381 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2382 && par->footnoteflag != footnoteflag) {
2383 par = par->TeXFootnote(buf, bparams,
2385 foot, foot_texrow, foot_count,
2387 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2393 // Make sure that \\par is done with the font of the last
2394 // character if this has another size as the default.
2395 // This is necessary because LaTeX (and LyX on the screen)
2396 // calculates the space between the baselines according
2397 // to this font. (Matthias)
2399 // Is this really needed ? (Dekel)
2400 // We do not need to use to change the font for the last paragraph
2401 // or for a command.
2403 LyXFont font = getFont(bparams, Last() - 1);
2405 LyXFont font = getFont(bparams, size() - 1);
2407 bool is_command = textclasslist.Style(bparams.textclass,
2408 GetLayout()).isCommand();
2409 if (style.resfont.size() != font.size() && next_ && !is_command) {
2412 os << "\\" << font.latexSize() << " \\par}";
2413 } else if (need_par) {
2415 } else if (is_command)
2418 if (language->babel() != doc_language->babel() &&
2421 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2423 || par->getParLanguage(bparams)->babel() != language->babel())) {
2425 << subst(lyxrc.language_command_end, "$$lang",
2426 doc_language->babel());
2429 switch (style.latextype) {
2430 case LATEX_ITEM_ENVIRONMENT:
2431 case LATEX_LIST_ENVIRONMENT:
2432 if (par && (params.depth() < par->params.depth())) {
2437 case LATEX_ENVIRONMENT:
2438 // if its the last paragraph of the current environment
2439 // skip it otherwise fall through
2441 && (par->layout != layout
2442 || par->params.depth() != params.depth()
2444 || par->params.pextraType() != params.pextraType()
2449 // we don't need it for the last paragraph!!!
2450 // or for tables in floats
2451 // -- effectively creates a \par where there isn't one which
2452 // breaks a \subfigure or \subtable.
2454 // && footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2460 further_blank_line = false;
2461 if (params.lineBottom()) {
2463 os << "\\lyxline{\\" << getFont(bparams,
2464 Last() - 1).latexSize() << '}';
2466 os << "\\lyxline{\\" << getFont(bparams,
2467 size() - 1).latexSize() << '}';
2469 further_blank_line = true;
2472 if (params.spaceBottom().kind() != VSpace::NONE) {
2473 os << params.spaceBottom().asLatexCommand(bparams);
2474 further_blank_line = true;
2477 if (params.pagebreakBottom()) {
2479 further_blank_line = true;
2482 if (further_blank_line){
2487 if (!params.spacing().isDefault()
2488 && (!par || !par->HasSameLayout(this))) {
2489 os << params.spacing().writeEnvirEnd() << "\n";
2493 // we don't need it for the last paragraph!!!
2496 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2497 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2504 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2509 // This one spits out the text of the paragraph
2510 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2511 BufferParams const & bparams,
2512 ostream & os, TexRow & texrow,
2515 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2517 bool return_value = false;
2519 LyXLayout const & style =
2520 textclasslist.Style(bparams.textclass,
2522 LyXFont basefont, last_font;
2524 // Maybe we have to create a optional argument.
2525 size_type main_body;
2526 if (style.labeltype != LABEL_MANUAL)
2529 main_body = BeginningOfMainBody();
2531 if (main_body > 0) {
2533 basefont = getFont(bparams, -2); // Get label font
2535 basefont = getFont(bparams, -1); // Get layout font
2546 if (style.isCommand()) {
2549 } else if (params.align() != LYX_ALIGN_LAYOUT) {
2552 return_value = true;
2556 moving_arg |= style.needprotect;
2558 // Which font is currently active?
2559 LyXFont running_font(basefont);
2560 // Do we have an open font change?
2561 bool open_font = false;
2563 texrow.start(this, 0);
2565 for (size_type i = 0; i < size(); ++i) {
2567 // First char in paragraph or after label?
2573 if (main_body > 0) {
2575 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2578 basefont = getFont(bparams, -1); // Now use the layout font
2579 running_font = basefont;
2583 if (style.isCommand()) {
2586 } else if (params.align() != LYX_ALIGN_LAYOUT && next_) {
2587 // We do not need \par here (Dekel)
2591 return_value = true;
2594 if (params.noindent()) {
2595 os << "\\noindent ";
2598 switch (params.align()) {
2599 case LYX_ALIGN_NONE:
2600 case LYX_ALIGN_BLOCK:
2601 case LYX_ALIGN_LAYOUT:
2602 case LYX_ALIGN_SPECIAL:
2604 case LYX_ALIGN_LEFT:
2607 if (getParLanguage(bparams)->babel() != "hebrew") {
2608 os << "\\raggedright ";
2611 os << "\\raggedleft ";
2615 case LYX_ALIGN_RIGHT:
2618 if (getParLanguage(bparams)->babel() != "hebrew") {
2619 os << "\\raggedleft ";
2622 os << "\\raggedright ";
2626 case LYX_ALIGN_CENTER:
2629 os << "\\centering ";
2635 value_type c = GetChar(i);
2637 // Fully instantiated font
2638 LyXFont font = getFont(bparams, i);
2640 LyXParagraph * p = 0;
2643 previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2644 (p = PreviousBeforeFootnote()) != 0)
2645 last_font = p->getFont(bparams, p->size() - 1);
2648 last_font = running_font;
2650 // Spaces at end of font change are simulated to be
2651 // outside font change, i.e. we write "\textXX{text} "
2652 // rather than "\textXX{text }". (Asger)
2653 if (open_font && c == ' ' && i <= size() - 2
2654 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2655 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2656 font = getFont(bparams, i + 1);
2658 // We end font definition before blanks
2659 if (!font.equalExceptLatex(running_font) && open_font) {
2660 column += running_font.latexWriteEndChanges(os,
2662 (i == main_body-1) ? basefont : font);
2663 running_font = basefont;
2667 // Blanks are printed before start of fontswitch
2669 // Do not print the separation of the optional argument
2670 if (i != main_body - 1) {
2671 SimpleTeXBlanks(os, texrow, i,
2672 column, font, style);
2676 // Do we need to change font?
2677 if (!font.equalExceptLatex(running_font)
2678 && i != main_body-1) {
2679 column += font.latexWriteStartChanges(os, basefont,
2681 running_font = font;
2685 if (c == LyXParagraph::META_NEWLINE) {
2686 // newlines are handled differently here than
2687 // the default in SimpleTeXSpecialChars().
2688 if (!style.newline_allowed
2689 || font.latex() == LyXFont::ON) {
2693 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2696 basefont = getFont(bparams, -1);
2697 running_font = basefont;
2698 if (font.family() ==
2699 LyXFont::TYPEWRITER_FAMILY) {
2707 texrow.start(this, i + 1);
2710 SimpleTeXSpecialChars(buf, bparams,
2711 os, texrow, moving_arg,
2712 font, running_font, basefont,
2713 open_font, style, i, column, c);
2717 // If we have an open font definition, we have to close it
2719 LyXParagraph * p = 0;
2722 && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
2723 && (p = NextAfterFootnote()) != 0
2728 running_font.latexWriteEndChanges(os, basefont,
2729 p->getFont(bparams, 0));
2731 running_font.latexWriteEndChanges(os, basefont, basefont);
2734 // Needed if there is an optional argument but no contents.
2735 if (main_body > 0 && main_body == size()) {
2737 return_value = false;
2740 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2741 return return_value;
2745 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2747 bool retval = false;
2749 case LyXParagraph::META_HFILL:
2750 sgml_string.erase();
2752 case LyXParagraph::META_NEWLINE:
2756 sgml_string = "&";
2759 sgml_string = "<";
2762 sgml_string = ">";
2765 sgml_string = "$";
2768 sgml_string = "#";
2771 sgml_string = "%";
2774 sgml_string = "[";
2777 sgml_string = "]";
2780 sgml_string = "{";
2783 sgml_string = "}";
2786 sgml_string = "˜";
2789 sgml_string = """;
2792 sgml_string = "\";
2798 case '\0': // Ignore :-)
2799 sgml_string.erase();
2809 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
2810 LyXParagraph::size_type const i,
2811 int & column, LyXFont const & font,
2812 LyXLayout const & style)
2814 if (column > tex_code_break_column
2816 && GetChar(i - 1) != ' '
2818 // In LaTeX mode, we don't want to
2819 // break lines since some commands
2821 && ! (font.latex() == LyXFont::ON)
2822 // same in FreeSpacing mode
2823 && !style.free_spacing
2824 // In typewriter mode, we want to avoid
2825 // ! . ? : at the end of a line
2826 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
2827 && (GetChar(i-1) == '.'
2828 || GetChar(i-1) == '?'
2829 || GetChar(i-1) == ':'
2830 || GetChar(i-1) == '!'))) {
2831 if (tex_code_break_column == 0) {
2832 // in batchmode we need LaTeX to still
2833 // see it as a space not as an extra '\n'
2839 texrow.start(this, i + 1);
2841 } else if (font.latex() == LyXFont::OFF) {
2842 if (style.free_spacing) {
2851 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
2852 BufferParams const & bparams,
2853 ostream & os, TexRow & texrow,
2856 LyXFont & running_font,
2859 LyXLayout const & style,
2860 LyXParagraph::size_type & i,
2862 LyXParagraph::value_type const c)
2864 // Two major modes: LaTeX or plain
2865 // Handle here those cases common to both modes
2866 // and then split to handle the two modes separately.
2868 case LyXParagraph::META_INSET: {
2869 Inset * inset = GetInset(i);
2872 int const len = os.tellp();
2873 //ostream::pos_type const len = os.tellp();
2874 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
2875 || inset->LyxCode() == Inset::MATH_CODE
2876 || inset->LyxCode() == Inset::URL_CODE)
2877 && running_font.isRightToLeft()) {
2882 int tmp = inset->Latex(buf, os, moving_arg,
2883 style.free_spacing);
2891 column += int(os.tellp()) - len;
2900 case LyXParagraph::META_NEWLINE:
2902 column += running_font.latexWriteEndChanges(os,
2907 basefont = getFont(bparams, -1);
2908 running_font = basefont;
2911 case LyXParagraph::META_HFILL:
2917 // And now for the special cases within each mode
2918 // Are we in LaTeX mode?
2919 if (font.latex() == LyXFont::ON) {
2920 // at present we only have one option
2921 // but I'll leave it as a switch statement
2922 // so its simpler to extend. (ARRae)
2925 // make sure that we will not print
2926 // error generating chars to the tex
2927 // file. This test would not be needed
2928 // if it were done in the buffer
2936 // Plain mode (i.e. not LaTeX)
2939 os << "\\textbackslash{}";
2943 case '°': case '±': case '²': case '³':
2944 case '×': case '÷': case '¹': case 'ª':
2945 case 'º': case '¬': case 'µ':
2946 if (bparams.inputenc == "latin1" ||
2947 (bparams.inputenc == "auto" &&
2948 font.language()->encoding()->LatexName()
2950 os << "\\ensuremath{"
2959 case '|': case '<': case '>':
2960 // In T1 encoding, these characters exist
2961 if (lyxrc.fontenc == "T1") {
2963 //... but we should avoid ligatures
2964 if ((c == '>' || c == '<')
2966 && GetChar(i + 1) == c) {
2967 //os << "\\textcompwordmark{}";
2968 // Jean-Marc, have a look at
2969 // this. IÂ think this works
2977 // Typewriter font also has them
2978 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
2982 // Otherwise, we use what LaTeX
2986 os << "\\textless{}";
2990 os << "\\textgreater{}";
2994 os << "\\textbar{}";
3000 case '-': // "--" in Typewriter mode -> "-{}-"
3002 && GetChar(i + 1) == '-'
3003 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3012 os << "\\char`\\\"{}";
3017 if (bparams.inputenc == "default") {
3026 case '%': case '#': case '{':
3033 os << "\\textasciitilde{}";
3038 os << "\\textasciicircum{}";
3042 case '*': case '[': case ']':
3043 // avoid being mistaken for optional arguments
3044 os << '{' << c << '}';
3049 // Blanks are printed before font switching.
3050 // Sure? I am not! (try nice-latex)
3051 // I am sure it's correct. LyX might be smarter
3052 // in the future, but for now, nothing wrong is
3057 /* idea for labels --- begin*/
3061 && font.family() != LyXFont::TYPEWRITER_FAMILY
3062 && GetChar(i + 1) == 'y'
3063 && GetChar(i + 2) == 'X') {
3071 && font.family() != LyXFont::TYPEWRITER_FAMILY
3072 && GetChar(i + 1) == 'e'
3073 && GetChar(i + 2) == 'X') {
3078 // Check for "LaTeX2e"
3081 && font.family() != LyXFont::TYPEWRITER_FAMILY
3082 && GetChar(i + 1) == 'a'
3083 && GetChar(i + 2) == 'T'
3084 && GetChar(i + 3) == 'e'
3085 && GetChar(i + 4) == 'X'
3086 && GetChar(i + 5) == '2'
3087 && GetChar(i + 6) == 'e') {
3092 // Check for "LaTeX"
3095 && font.family() != LyXFont::TYPEWRITER_FAMILY
3096 && GetChar(i + 1) == 'a'
3097 && GetChar(i + 2) == 'T'
3098 && GetChar(i + 3) == 'e'
3099 && GetChar(i + 4) == 'X') {
3103 /* idea for labels --- end*/
3104 } else if (c != '\0') {
3114 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3115 BufferParams const & bparams,
3116 ostream & os, TexRow & texrow
3119 TexRow & foot_texrow,
3124 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3125 LyXParagraph * par = this;
3128 (par->params.depth() == params.depth())
3130 && (par->footnoteflag == footnoteflag)
3135 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3137 if (textclasslist.Style(bparams.textclass,
3138 par->layout).isEnvironment()
3140 || par->params.pextraType() != PEXTRA_NONE
3143 par = par->TeXEnvironment(buf, bparams,
3151 par = par->TeXOnePar(buf, bparams,
3161 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3167 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3168 BufferParams const & bparams,
3169 ostream & os, TexRow & texrow
3172 TexRow & foot_texrow,
3178 bool eindent_open = false;
3181 bool foot_this_level = false;
3184 // flags when footnotetext should be appended to file.
3185 static bool minipage_open = false;
3186 static int minipage_open_depth = 0;
3187 char par_sep = bparams.paragraph_separation;
3190 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3193 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3196 LyXLayout const & style =
3197 textclasslist.Style(bparams.textclass,
3201 if (params.pextraType() == PEXTRA_INDENT) {
3202 if (!params.pextraWidth().empty()) {
3203 os << "\\begin{LyXParagraphIndent}{"
3204 << params.pextraWidth() << "}\n";
3206 //float ib = atof(pextra_widthp.c_str())/100;
3207 // string can't handle floats at present (971109)
3208 // so I'll do a conversion by hand knowing that
3209 // the limits are 0.0 to 1.0. ARRae.
3210 os << "\\begin{LyXParagraphIndent}{";
3211 switch (params.pextraWidthp().length()) {
3217 << params.pextraWidthp();
3221 << params.pextraWidthp();
3223 os << "\\columnwidth}\n";
3226 eindent_open = true;
3228 if ((params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
3229 if (params.pextraHfill() && previous() &&
3230 (previous()->params.pextraType() == PEXTRA_MINIPAGE)) {
3231 os << "\\hfill{}\n";
3234 if (par_sep == BufferParams::PARSEP_INDENT) {
3235 os << "{\\setlength\\parindent{0pt}\n";
3238 os << "\\begin{minipage}";
3239 switch (params.pextraAlignment()) {
3240 case MINIPAGE_ALIGN_TOP:
3243 case MINIPAGE_ALIGN_MIDDLE:
3246 case MINIPAGE_ALIGN_BOTTOM:
3250 if (!params.pextraWidth().empty()) {
3251 os << '{' << params.pextraWidth() << "}\n";
3253 //float ib = atof(par->pextra_width.c_str())/100;
3254 // string can't handle floats at present
3255 // so I'll do a conversion by hand knowing that
3256 // the limits are 0.0 to 1.0. ARRae.
3258 switch (params.pextraWidthp().length()) {
3264 << params.pextraWidthp();
3268 << params.pextraWidthp();
3270 os << "\\columnwidth}\n";
3273 if (par_sep == BufferParams::PARSEP_INDENT) {
3274 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3277 minipage_open = true;
3278 minipage_open_depth = params.depth();
3281 #ifdef WITH_WARNINGS
3282 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3283 //I disabled it because it breaks when lists span on several
3286 if (style.isEnvironment()){
3287 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3288 #ifdef FANCY_FOOTNOTE_CODE
3289 if (foot_count < 0) {
3290 // flag that footnote[mark][text] should be
3291 // used for any footnotes from now on
3293 foot_this_level = true;
3296 os << "\\begin{" << style.latexname() << "}{"
3297 << params.labelWidthString() << "}\n";
3298 } else if (style.labeltype == LABEL_BIBLIO) {
3300 os << "\\begin{" << style.latexname() << "}{"
3301 << bibitemWidest(buf)
3303 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3304 #ifdef FANCY_FOOTNOTE_CODE
3305 if (foot_count < 0) {
3306 // flag that footnote[mark][text] should be
3307 // used for any footnotes from now on
3309 foot_this_level = true;
3312 os << "\\begin{" << style.latexname() << '}'
3313 << style.latexparam() << '\n';
3315 os << "\\begin{" << style.latexname() << '}'
3316 << style.latexparam() << '\n';
3319 LyXParagraph * par = this;
3321 par = par->TeXOnePar(buf, bparams,
3325 foot, foot_texrow, foot_count
3329 if (minipage_open && par && !style.isEnvironment() &&
3330 (par->params.pextraType() == PEXTRA_MINIPAGE) &&
3331 par->params.pextraStartMinipage()) {
3332 os << "\\end{minipage}\n";
3334 if (par_sep == BufferParams::PARSEP_INDENT) {
3338 minipage_open = false;
3341 if (par && par->params.depth() > params.depth()) {
3342 if (textclasslist.Style(bparams.textclass,
3343 par->layout).isParagraph()
3345 // How to handle this? (Lgb)
3346 //&& !suffixIs(os, "\n\n")
3348 // There should be at least one '\n' already
3349 // but we need there to be two for Standard
3350 // paragraphs that are depth-increment'ed to be
3351 // output correctly. However, tables can
3352 // also be paragraphs so don't adjust them.
3355 // Will it ever harm to have one '\n' too
3356 // many? i.e. that we sometimes will have
3357 // three in a row. (Lgb)
3361 par = par->TeXDeeper(buf, bparams, os, texrow
3363 ,foot, foot_texrow, foot_count
3368 if (par && par->layout == layout && par->params.depth() == params.depth() &&
3369 (par->params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
3370 if (par->params.pextraHfill() && par->previous() &&
3371 (par->previous()->params.pextraType() == PEXTRA_MINIPAGE)){
3372 os << "\\hfill{}\n";
3375 if (par_sep == BufferParams::PARSEP_INDENT) {
3376 os << "{\\setlength\\parindent{0pt}\n";
3379 os << "\\begin{minipage}";
3380 switch (par->params.pextraAlignment()) {
3381 case MINIPAGE_ALIGN_TOP:
3384 case MINIPAGE_ALIGN_MIDDLE:
3387 case MINIPAGE_ALIGN_BOTTOM:
3391 if (!par->params.pextraWidth().empty()) {
3392 os << '{' << par->params.pextraWidth() << "}\n";
3394 //float ib = atof(par->pextra_widthp.c_str())/100;
3395 // string can't handle floats at present
3396 // so I'll do a conversion by hand knowing that
3397 // the limits are 0.0 to 1.0. ARRae.
3399 switch (par->params.pextraWidthp().length()) {
3404 os << "0." << par->params.pextraWidthp();
3407 os << "0.0" << par->params.pextraWidthp();
3409 os << "\\columnwidth}\n";
3412 if (par_sep == BufferParams::PARSEP_INDENT) {
3413 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3416 minipage_open = true;
3417 minipage_open_depth = par->params.depth();
3421 && par->layout == layout
3422 && par->params.depth() == params.depth()
3424 && par->params.pextraType() == params.pextraType()
3427 && par->footnoteflag == footnoteflag
3431 if (style.isEnvironment()) {
3432 os << "\\end{" << style.latexname() << "}\n";
3435 // maybe this should go after the minipage closes?
3436 if (foot_this_level) {
3437 if (foot_count >= 1) {
3438 if (foot_count > 1) {
3439 os << "\\addtocounter{footnote}{-"
3444 texrow += foot_texrow;
3446 foot_texrow.reset();
3453 if (minipage_open && (minipage_open_depth == params.depth()) &&
3454 (!par || par->params.pextraStartMinipage() ||
3455 par->params.pextraType() != PEXTRA_MINIPAGE)) {
3456 os << "\\end{minipage}\n";
3458 if (par_sep == BufferParams::PARSEP_INDENT) {
3462 if (par && par->params.pextraType() != PEXTRA_MINIPAGE) {
3463 os << "\\medskip\n\n";
3467 minipage_open = false;
3470 os << "\\end{LyXParagraphIndent}\n";
3473 if (!(par && (par->params.pextraType() == PEXTRA_MINIPAGE)
3474 && par->params.pextraHfill())) {
3479 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3480 return par; // ale970302
3485 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3486 BufferParams const & bparams,
3487 ostream & os, TexRow & texrow,
3488 ostream & foot, TexRow & foot_texrow,
3492 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3493 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3494 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3495 "No footnote!" << endl;
3497 LyXParagraph * par = this;
3498 LyXLayout const & style =
3499 textclasslist.Style(bparams.textclass,
3500 previous_->GetLayout());
3502 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3503 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3504 "Float other than footnote in command"
3505 " with moving argument is illegal" << endl;
3508 if (footnotekind != LyXParagraph::FOOTNOTE
3509 && footnotekind != LyXParagraph::MARGIN
3512 // How to solve this?
3513 //&& !suffixIs(file, '\n')
3515 // we need to ensure that real floats like tables and figures
3516 // have their \begin{} on a new line otherwise we can get
3517 // incorrect results when using the endfloat.sty package
3518 // especially if two floats follow one another. ARRae 981022
3519 // NOTE: if the file is length 0 it must have just been
3520 // written out so we assume it ended with a '\n'
3522 // As far as I can see there is never any harm in writing
3523 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3528 bool moving_arg = false;
3529 bool need_closing = false;
3530 bool is_rtl = isRightToLeftPar(bparams);
3532 if (is_rtl != parent_is_rtl) {
3537 need_closing = true;
3540 bool footer_in_body = true;
3541 switch (footnotekind) {
3542 case LyXParagraph::FOOTNOTE:
3543 if (style.intitle) {
3544 os << "\\thanks{\n";
3545 footer_in_body = false;
3548 if (foot_count == -1) {
3549 // we're at depth 0 so we can use:
3550 os << "\\footnote{%\n";
3551 footer_in_body = false;
3553 os << "\\footnotemark{}%\n";
3555 // we only need this when there are
3556 // multiple footnotes
3557 os << "\\stepcounter{footnote}";
3559 os << "\\footnotetext{%\n";
3560 foot_texrow.start(this, 0);
3561 foot_texrow.newline();
3566 case LyXParagraph::MARGIN:
3567 os << "\\marginpar{\n";
3569 case LyXParagraph::FIG:
3570 if (params.pextraType() == PEXTRA_FLOATFLT
3571 && (!params.pextraWidth().empty()
3572 || !params.pextraWidthp().empty())) {
3573 if (!params.pextraWidth().empty())
3574 os << "\\begin{floatingfigure}{"
3575 << params.pextraWidth() << "}\n";
3577 os << "\\begin{floatingfigure}{"
3578 << lyx::atoi(params.pextraWidthp()) / 100.0
3579 << "\\textwidth}\n";
3581 os << "\\begin{figure}";
3582 if (!bparams.float_placement.empty()) {
3583 os << '[' << bparams.float_placement << "]\n";
3589 case LyXParagraph::TAB:
3590 os << "\\begin{table}";
3591 if (!bparams.float_placement.empty()) {
3592 os << '[' << bparams.float_placement << "]\n";
3597 case LyXParagraph::WIDE_FIG:
3598 os << "\\begin{figure*}";
3599 if (!bparams.float_placement.empty()) {
3600 os << '[' << bparams.float_placement << "]\n";
3605 case LyXParagraph::WIDE_TAB:
3606 os << "\\begin{table*}";
3607 if (!bparams.float_placement.empty()) {
3608 os << '[' << bparams.float_placement << "]\n";
3613 case LyXParagraph::ALGORITHM:
3614 os << "\\begin{algorithm}\n";
3619 if (footnotekind != LyXParagraph::FOOTNOTE
3620 || !footer_in_body) {
3621 // Process text for all floats except footnotes in body
3623 LyXLayout const & style =
3625 .Style(bparams.textclass, par->layout);
3627 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3629 if (style.isEnvironment()
3630 || par->params.pextraType() == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3631 // Allows the use of minipages within float
3632 // environments. Shouldn't be circular because
3633 // we don't support footnotes inside
3634 // floats (yet). ARRae
3635 par = par->TeXEnvironment(buf, bparams, os,
3640 par = par->TeXOnePar(buf, bparams,
3641 os, texrow, moving_arg,
3646 if (par && !par->IsDummy() && par->params.depth() > params.depth()) {
3647 par = par->TeXDeeper(buf, bparams, os, texrow,
3651 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3653 // process footnotes > depth 0 or in environments separately
3654 // NOTE: Currently don't support footnotes within footnotes
3655 // even though that is possible using the \footnotemark
3656 std::ostringstream dummy;
3657 TexRow dummy_texrow;
3658 int dummy_count = 0;
3660 LyXLayout const & style =
3662 .Style(bparams.textclass, par->layout);
3664 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3666 if (style.isEnvironment()
3667 || par->params.pextraType() == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3668 // Allows the use of minipages within float
3669 // environments. Shouldn't be circular because
3670 // we don't support footnotes inside
3671 // floats (yet). ARRae
3672 par = par->TeXEnvironment(buf, bparams,
3674 dummy, dummy_texrow,
3677 par = par->TeXOnePar(buf, bparams,
3680 dummy, dummy_texrow,
3684 if (par && !par->IsDummy() && par->params.depth() > params.depth()) {
3685 par = par->TeXDeeper(buf, bparams,
3687 dummy, dummy_texrow,
3691 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3693 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3694 "Footnote in a Footnote -- not supported"
3699 switch (footnotekind) {
3700 case LyXParagraph::FOOTNOTE:
3701 if (footer_in_body) {
3702 // This helps tell which of the multiple
3703 // footnotetexts an error was in.
3705 foot_texrow.newline();
3710 case LyXParagraph::MARGIN:
3713 case LyXParagraph::FIG:
3714 if (params.pextraType() == PEXTRA_FLOATFLT
3715 && (!params.pextraWidth().empty()
3716 || !params.pextraWidthp().empty()))
3717 os << "\\end{floatingfigure}";
3719 os << "\\end{figure}";
3721 case LyXParagraph::TAB:
3722 os << "\\end{table}";
3724 case LyXParagraph::WIDE_FIG:
3725 os << "\\end{figure*}";
3727 case LyXParagraph::WIDE_TAB:
3728 os << "\\end{table*}";
3730 case LyXParagraph::ALGORITHM:
3731 os << "\\end{algorithm}";
3738 if (footnotekind != LyXParagraph::FOOTNOTE
3739 && footnotekind != LyXParagraph::MARGIN) {
3740 // we need to ensure that real floats like tables and figures
3741 // have their \end{} on a line of their own otherwise we can
3742 // get incorrect results when using the endfloat.sty package.
3747 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next_ << endl;
3752 bool LyXParagraph::IsDummy() const
3754 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous_
3755 && previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3760 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
3761 int type, string const & width,
3762 string const & widthp)
3764 params.pextraType(type);
3765 params.pextraWidth(width);
3766 params.pextraWidthp(widthp);
3768 if (textclasslist.Style(bparams.textclass,
3769 layout).isEnvironment()) {
3770 LyXParagraph * par = this;
3771 LyXParagraph * ppar = par;
3773 while (par && (par->layout == layout)
3774 && (par->params.depth() == params.depth())) {
3776 par = par->previous();
3779 par = par->FirstPhysicalPar();
3781 while (par && par->params.depth() > params.depth()) {
3782 par = par->previous();
3785 par = par->FirstPhysicalPar();
3790 while (par && (par->layout == layout)
3791 && (par->params.depth() == params.depth())) {
3792 par->params.pextraType(type);
3793 par->params.pextraWidth(width);
3794 par->params.pextraWidthp(widthp);
3796 par = par->NextAfterFootnote();
3800 if (par && (par->params.depth() > params.depth()))
3801 par->SetPExtraType(bparams,
3802 type, width, widthp);
3804 while (par && ((par->params.depth() > params.depth()) || par->IsDummy()))
3805 par = par->NextAfterFootnote();
3807 while (par && par->params.depth() > params.depth())
3815 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
3817 if (params.pextraType() == PEXTRA_NONE)
3820 params.pextraType(PEXTRA_NONE);
3821 params.pextraWidth(string());
3822 params.pextraWidthp(string());
3824 if (textclasslist.Style(bparams.textclass,
3825 layout).isEnvironment()) {
3826 LyXParagraph * par = this;
3827 LyXParagraph * ppar = par;
3829 while (par && (par->layout == layout)
3830 && (par->params.depth() == params.depth())) {
3832 par = par->previous();
3835 par = par->FirstPhysicalPar();
3837 while (par && par->params.depth() > params.depth()) {
3838 par = par->previous();
3841 par = par->FirstPhysicalPar();
3846 while (par && (par->layout == layout)
3847 && (par->params.depth() == params.depth())) {
3848 par->params.pextraType(PEXTRA_NONE);
3849 par->params.pextraWidth(string());
3850 par->params.pextraWidthp(string());
3852 par = par->NextAfterFootnote();
3856 if (par && (par->params.depth() > params.depth()))
3857 par->UnsetPExtraType(bparams);
3859 while (par && ((par->params.depth() > params.depth()) || par->IsDummy()))
3860 par = par->NextAfterFootnote();
3862 while (par && par->params.depth() > params.depth())
3871 bool LyXParagraph::IsHfill(size_type pos) const
3873 return IsHfillChar(GetChar(pos));
3877 bool LyXParagraph::IsInset(size_type pos) const
3879 return IsInsetChar(GetChar(pos));
3884 bool LyXParagraph::IsFloat(size_type pos) const
3886 return IsFloatChar(GetChar(pos));
3891 bool LyXParagraph::IsNewline(size_type pos) const
3893 return pos >= 0 && IsNewlineChar(GetChar(pos));
3897 bool LyXParagraph::IsSeparator(size_type pos) const
3899 return IsSeparatorChar(GetChar(pos));
3903 bool LyXParagraph::IsLineSeparator(size_type pos) const
3905 return IsLineSeparatorChar(GetChar(pos));
3909 bool LyXParagraph::IsKomma(size_type pos) const
3911 return IsKommaChar(GetChar(pos));
3915 /// Used by the spellchecker
3916 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
3918 value_type const c = GetChar(pos);
3919 if (IsLetterChar(c))
3921 // '\0' is not a letter, allthough every string contains "" (below)
3924 // We want to pass the ' and escape chars to ispell
3925 string const extra = lyxrc.isp_esc_chars + '\'';
3926 char ch[2] = { c, 0 };
3927 return contains(extra, ch);
3931 bool LyXParagraph::IsWord(size_type pos ) const
3933 return IsWordChar(GetChar(pos)) ;
3938 LyXParagraph::getParLanguage(BufferParams const & bparams) const
3942 return FirstPhysicalPar()->getParLanguage(bparams);
3946 return GetFirstFontSettings().language();
3948 return previous_->getParLanguage(bparams);
3950 return bparams.language;
3954 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
3956 return lyxrc.rtl_support
3957 && getParLanguage(bparams)->RightToLeft();
3961 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
3962 Language const * from, Language const * to)
3964 for (size_type i = 0; i < size(); ++i) {
3965 LyXFont font = GetFontSettings(bparams, i);
3966 if (font.language() == from) {
3967 font.setLanguage(to);
3974 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
3976 Language const * doc_language = bparams.language;
3977 for (FontList::const_iterator cit = fontlist.begin();
3978 cit != fontlist.end(); ++cit)
3979 if ((*cit).font().language() != doc_language)
3985 // Convert the paragraph to a string.
3986 // Used for building the table of contents
3987 string const LyXParagraph::String(Buffer const * buffer, bool label)
3989 BufferParams const & bparams = buffer->params;
3992 if (label && !IsDummy() && !params.labelString().empty())
3994 if (label && !params.labelString().empty())
3996 s += params.labelString() + ' ';
3997 string::size_type const len = s.size();
3999 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4000 value_type c = GetChar(i);
4003 else if (c == META_INSET &&
4004 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4005 std::ostringstream ost;
4006 GetInset(i)->Ascii(buffer, ost);
4007 s += subst(ost.str().c_str(),'\n',' ');
4012 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
4013 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4014 s += NextAfterFootnote()->String(buffer, false);
4018 if (isRightToLeftPar(bparams))
4019 reverse(s.begin() + len,s.end());
4027 string const LyXParagraph::String(Buffer const * buffer,
4028 LyXParagraph::size_type beg,
4029 LyXParagraph::size_type end)
4034 if (beg == 0 && !IsDummy() && !params.labelString().empty())
4036 if (beg == 0 && !params.labelString().empty())
4038 s += params.labelString() + ' ';
4040 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4041 value_type c = GetUChar(buffer->params, i);
4044 else if (c == META_INSET) {
4045 std::ostringstream ost;
4046 GetInset(i)->Ascii(buffer, ost);
4047 s += ost.str().c_str();
4055 void LyXParagraph::SetInsetOwner(Inset * i)
4058 for (InsetList::const_iterator cit = insetlist.begin();
4059 cit != insetlist.end(); ++cit) {
4061 (*cit).inset->setOwner(i);
4066 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4069 for (InsetList::const_iterator cit = insetlist.begin();
4070 cit != insetlist.end(); ++cit) {
4072 if ((*cit).inset->IsTextInset()) {
4073 static_cast<UpdatableInset *>
4074 ((*cit).inset)->deleteLyXText(bv);
4081 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4084 for (InsetList::const_iterator cit = insetlist.begin();
4085 cit != insetlist.end(); ++cit) {
4087 if ((*cit).inset->IsTextInset()) {
4088 static_cast<UpdatableInset *>
4089 ((*cit).inset)->resizeLyXText(bv);
4096 void LyXParagraph::fitToSize()
4098 TextContainer tmp(text.begin(), text.end());
4103 void LyXParagraph::setContentsFromPar(LyXParagraph * par)