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"
26 #include "tex-strings.h"
28 #include "bufferparams.h"
29 #include "support/FileInfo.h"
30 #include "support/LAssert.h"
32 #include "LaTeXFeatures.h"
33 #include "insets/insetinclude.h"
34 #include "insets/insetbib.h"
35 #include "insets/insettext.h"
36 #include "support/filetools.h"
37 #include "lyx_gui_misc.h"
39 #include "support/lyxmanip.h"
40 #include "BufferView.h"
42 #include "ParameterStruct.h"
49 using std::lower_bound;
50 using std::upper_bound;
53 int tex_code_break_column = 72; // needs non-zero initialization. set later.
54 // this is a bad idea, but how can LyXParagraph find its buffer to get
55 // parameters? (JMarc)
57 extern string bibitemWidest(Buffer const *);
59 // this is a minibuffer
64 LyXFont minibuffer_font;
65 Inset * minibuffer_inset;
70 extern BufferView * current_view;
72 // Initialization of the counter for the paragraph id's,
73 // declared in lyxparagraph.h
74 unsigned int LyXParagraph::paragraph_id = 0;
76 // Initialize static member.
77 ShareContainer<LyXFont> LyXParagraph::FontTable::container;
80 LyXParagraph::LyXParagraph()
82 text.reserve(500); // is this number too big?
83 for (int i = 0; i < 10; ++i) setCounter(i , 0);
89 footnoteflag = LyXParagraph::NO_FOOTNOTE;
90 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
95 bibkey = 0; // ale970302
100 // This konstruktor inserts the new paragraph in a list.
101 LyXParagraph::LyXParagraph(LyXParagraph * par)
106 for (int i = 0; i < 10; ++i) setCounter(i, 0);
109 // double linked list begin
112 next_->previous_ = this;
114 previous_->next_ = this;
117 footnoteflag = LyXParagraph::NO_FOOTNOTE;
118 footnotekind = LyXParagraph::FOOTNOTE;
121 id_ = paragraph_id++;
123 bibkey = 0; // ale970302
129 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
130 BufferParams const & bparams,
131 char footflag, char dth) const
134 if (footnoteflag != LyXParagraph::NO_FOOTNOTE ||
136 || previous_->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
137 // The beginning or the end of a footnote environment?
138 if (footflag != footnoteflag) {
139 footflag = footnoteflag;
141 os << "\n\\begin_float "
142 << string_footnotekinds[footnotekind]
145 os << "\n\\end_float ";
149 // The beginning or end of a deeper (i.e. nested) area?
150 if (dth != params.depth()) {
151 if (params.depth() > dth) {
152 while (params.depth() > dth) {
153 os << "\n\\begin_deeper ";
157 while (params.depth() < dth) {
158 os << "\n\\end_deeper ";
164 // First write the layout
166 << textclasslist.NameOfLayout(bparams.textclass, layout)
169 // Maybe some vertical spaces.
170 if (params.spaceTop().kind() != VSpace::NONE)
171 os << "\\added_space_top "
172 << params.spaceTop().asLyXCommand() << " ";
173 if (params.spaceBottom().kind() != VSpace::NONE)
174 os << "\\added_space_bottom "
175 << params.spaceBottom().asLyXCommand() << " ";
177 // Maybe the paragraph has special spacing
178 params.spacing().writeFile(os, true);
180 // The labelwidth string used in lists.
181 if (!params.labelWidthString().empty())
182 os << "\\labelwidthstring "
183 << params.labelWidthString() << '\n';
185 // Lines above or below?
186 if (params.lineTop())
188 if (params.lineBottom())
189 os << "\\line_bottom ";
191 // Pagebreaks above or below?
192 if (params.pagebreakTop())
193 os << "\\pagebreak_top ";
194 if (params.pagebreakBottom())
195 os << "\\pagebreak_bottom ";
197 // Start of appendix?
198 if (params.startOfAppendix())
199 os << "\\start_of_appendix ";
202 if (params.noindent())
206 if (params.align() != LYX_ALIGN_LAYOUT) {
208 switch (params.align()) {
209 case LYX_ALIGN_LEFT: h = 1; break;
210 case LYX_ALIGN_RIGHT: h = 2; break;
211 case LYX_ALIGN_CENTER: h = 3; break;
212 default: h = 0; break;
214 os << "\\align " << string_align[h] << " ";
217 if (params.pextraType() != PEXTRA_NONE) {
218 os << "\\pextra_type " << params.pextraType();
219 if (params.pextraType() == PEXTRA_MINIPAGE) {
220 os << " \\pextra_alignment "
221 << params.pextraAlignment();
222 if (params.pextraHfill())
223 os << " \\pextra_hfill "
224 << params.pextraHfill();
225 if (params.pextraStartMinipage())
226 os << " \\pextra_start_minipage "
227 << params.pextraStartMinipage();
229 if (!params.pextraWidth().empty()) {
230 os << " \\pextra_width "
231 << VSpace(params.pextraWidth()).asLyXCommand();
232 } else if (!params.pextraWidthp().empty()) {
233 os << " \\pextra_widthp "
234 << params.pextraWidthp();
241 // Dummy layout. This means that a footnote ended.
242 os << "\n\\end_float ";
243 footflag = LyXParagraph::NO_FOOTNOTE;
249 bibkey->Write(buf, os);
251 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
254 for (size_type i = 0; i < size(); ++i) {
260 // Write font changes
261 LyXFont font2 = GetFontSettings(bparams, i);
262 if (font2 != font1) {
263 font2.lyxWriteChanges(font1, os);
268 value_type const c = GetChar(i);
272 Inset const * inset = GetInset(i);
274 if (inset->DirectWrite()) {
275 // international char, let it write
276 // code directly so it's shorter in
278 inset->Write(buf, os);
280 os << "\n\\begin_inset ";
281 inset->Write(buf, os);
282 os << "\n\\end_inset \n\n";
288 os << "\n\\newline \n";
292 os << "\n\\hfill \n";
296 os << "\n\\backslash \n";
300 if (i + 1 < size() && GetChar(i + 1) == ' ') {
307 if ((column > 70 && c == ' ')
312 // this check is to amend a bug. LyX sometimes
313 // inserts '\0' this could cause problems.
317 lyxerr << "ERROR (LyXParagraph::writeFile):"
318 " NULL char in structure." << endl;
324 // now write the next paragraph
326 next_->writeFile(buf, os, bparams, footflag, dth);
330 void LyXParagraph::validate(LaTeXFeatures & features) const
332 BufferParams const & bparams = features.bufferParams();
335 // this will be useful later
336 LyXLayout const & layout =
337 textclasslist.Style(bparams.textclass,
342 if (params.lineTop() || params.lineBottom())
343 features.lyxline = true;
344 if (!params.spacing().isDefault())
345 features.setspace = true;
348 features.layout[GetLayout()] = true;
351 Language const * doc_language = bparams.language;
353 for (FontList::const_iterator cit = fontlist.begin();
354 cit != fontlist.end(); ++cit) {
355 if ((*cit).font().noun() == LyXFont::ON) {
356 lyxerr[Debug::LATEX] << "font.noun: "
357 << (*cit).font().noun()
359 features.noun = true;
360 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
361 << (*cit).font().stateText(0)
364 switch ((*cit).font().color()) {
366 case LColor::inherit:
370 features.color = true;
371 lyxerr[Debug::LATEX] << "Color enabled. Font: "
372 << (*cit).font().stateText(0)
376 Language const * language = (*cit).font().language();
377 if (language->babel() != doc_language->babel()) {
378 features.UsedLanguages.insert(language);
379 lyxerr[Debug::LATEX] << "Found language "
380 << language->babel() << endl;
385 for (InsetList::const_iterator cit = insetlist.begin();
386 cit != insetlist.end(); ++cit) {
388 (*cit).inset->Validate(features);
392 if (params.pextraType() == PEXTRA_INDENT)
393 features.LyXParagraphIndent = true;
394 if (params.pextraType() == PEXTRA_FLOATFLT)
395 features.floatflt = true;
398 if (layout.needprotect
399 && next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
400 features.NeedLyXFootnoteCode = true;
403 if (bparams.paragraph_separation == BufferParams::PARSEP_INDENT
404 && params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE)
405 features.NeedLyXMinipageIndent = true;
408 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
409 features.algorithm = true;
414 // First few functions needed for cut and paste and paragraph breaking.
415 void LyXParagraph::CopyIntoMinibuffer(Buffer const & buffer,
416 LyXParagraph::size_type pos) const
418 BufferParams bparams = buffer.params;
420 minibuffer_char = GetChar(pos);
421 minibuffer_font = GetFontSettings(bparams, pos);
422 minibuffer_inset = 0;
423 if (minibuffer_char == LyXParagraph::META_INSET) {
425 minibuffer_inset = GetInset(pos)->Clone(buffer);
427 minibuffer_inset = 0;
428 minibuffer_char = ' ';
429 // This reflects what GetInset() does (ARRae)
435 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
436 LyXParagraph::size_type pos)
438 minibuffer_char = GetChar(pos);
439 minibuffer_font = GetFontSettings(bparams, pos);
440 minibuffer_inset = 0;
441 if (minibuffer_char == LyXParagraph::META_INSET) {
443 minibuffer_inset = GetInset(pos);
444 // This is a little hack since I want exactly
445 // the inset, not just a clone. Otherwise
446 // the inset would be deleted when calling Erase(pos)
448 InsetTable search_elem(pos, 0);
449 InsetList::iterator it =
450 lower_bound(insetlist.begin(),
452 search_elem, matchIT());
453 if (it != insetlist.end() && (*it).pos == pos)
456 minibuffer_inset = 0;
457 minibuffer_char = ' ';
458 // This reflects what GetInset() does (ARRae)
463 // Erase(pos); now the caller is responsible for that.
467 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
469 if ((minibuffer_char == LyXParagraph::META_INSET) &&
470 !InsertInsetAllowed(minibuffer_inset))
472 if (minibuffer_char == LyXParagraph::META_INSET)
473 InsertInset(pos, minibuffer_inset, minibuffer_font);
475 InsertChar(pos, minibuffer_char, minibuffer_font);
483 void LyXParagraph::Clear()
492 // the destructor removes the new paragraph from the list
493 LyXParagraph::~LyXParagraph()
496 previous_->next_ = next_;
498 next_->previous_ = previous_;
500 for (InsetList::iterator it = insetlist.begin();
501 it != insetlist.end(); ++it) {
508 //lyxerr << "LyXParagraph::paragraph_id = "
509 // << LyXParagraph::paragraph_id << endl;
513 void LyXParagraph::Erase(LyXParagraph::size_type pos)
516 // > because last is the next unused position, and you can
517 // use it if you want
519 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
520 NextAfterFootnote()->Erase(pos - text.size() - 1);
522 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
523 "position does not exist." << endl;
527 lyx::Assert(pos < size());
530 if (pos < size()) { // last is free for insertation, but should be empty
532 // if it is an inset, delete the inset entry
533 if (text[pos] == LyXParagraph::META_INSET) {
535 InsetTable search_inset(pos, 0);
536 InsetList::iterator it =
537 lower_bound(insetlist.begin(),
539 search_inset, matchIT());
540 if (it != insetlist.end() && (*it).pos == pos) {
546 text.erase(text.begin() + pos);
548 // Erase entries in the tables.
549 FontTable search_font(pos, LyXFont());
551 FontList::iterator it =
552 lower_bound(fontlist.begin(),
554 search_font, matchFT());
555 if (it != fontlist.end() && (*it).pos() == pos &&
557 (it != fontlist.begin() && (*(it - 1)).pos() == pos - 1))) {
558 // If it is a multi-character font
559 // entry, we just make it smaller
560 // (see update below), otherwise we
562 unsigned int const i = it - fontlist.begin();
563 fontlist.erase(fontlist.begin() + i);
564 it = fontlist.begin() + i;
565 if (i > 0 && i < fontlist.size() &&
566 fontlist[i - 1].font() == fontlist[i].font()) {
567 fontlist.erase(fontlist.begin() + i - 1);
568 it = fontlist.begin() + i - 1;
572 // Update all other entries.
573 FontList::iterator fend = fontlist.end();
574 for (; it != fend; ++it)
575 (*it).pos((*it).pos() - 1);
577 // Update the inset table.
578 InsetTable search_inset(pos, 0);
579 InsetList::iterator lend = insetlist.end();
580 for (InsetList::iterator it =
581 upper_bound(insetlist.begin(),
583 search_inset, matchIT());
588 lyxerr << "ERROR (LyXParagraph::Erase): "
589 "can't erase non-existant char." << endl;
595 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
596 LyXParagraph::value_type c)
598 LyXFont const f(LyXFont::ALL_INHERIT);
599 InsertChar(pos, c, f);
603 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
604 LyXParagraph::value_type c,
605 LyXFont const & font)
608 // > because last is the next unused position, and you can
609 // use it if you want
612 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
613 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
616 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
617 "position does not exist." << endl;
621 lyx::Assert(pos <= size());
623 text.insert(text.begin() + pos, c);
625 // Update the font table.
626 FontTable search_font(pos, LyXFont());
627 for (FontList::iterator it = lower_bound(fontlist.begin(),
629 search_font, matchFT());
630 it != fontlist.end(); ++it)
631 (*it).pos((*it).pos() + 1);
633 // Update the inset table.
634 InsetTable search_inset(pos, 0);
635 for (InsetList::iterator it = lower_bound(insetlist.begin(),
637 search_inset, matchIT());
638 it != insetlist.end(); ++it)
645 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
648 LyXFont const f(LyXFont::ALL_INHERIT);
649 InsertInset(pos, inset, f);
653 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
654 Inset * inset, LyXFont const & font)
659 // > because last is the next unused position, and you can
660 // use it if you want
663 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
665 ->InsertInset(pos - text.size() - 1,
668 lyxerr << "ERROR (LyXParagraph::InsertInset): "
669 "position does not exist: " << pos << endl;
673 lyx::Assert(pos <= size());
676 InsertChar(pos, META_INSET, font);
677 lyx::Assert(text[pos] == META_INSET);
679 // Add a new entry in the inset table.
680 InsetTable search_inset(pos, 0);
681 InsetList::iterator it = lower_bound(insetlist.begin(),
683 search_inset, matchIT());
684 if (it != insetlist.end() && (*it).pos == pos)
685 lyxerr << "ERROR (LyXParagraph::InsertInset): "
686 "there is an inset in position: " << pos << endl;
688 insetlist.insert(it, InsetTable(pos, inset));
690 inset->setOwner(inset_owner);
694 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
696 //lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
699 return inset_owner->InsertInsetAllowed(inset);
704 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
709 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
710 return NextAfterFootnote()
711 ->GetInset(pos - text.size() - 1);
713 lyxerr << "ERROR (LyXParagraph::GetInset): "
714 "position does not exist: "
720 lyx::Assert(pos < size());
723 InsetTable search_inset(pos, 0);
724 InsetList::iterator it = lower_bound(insetlist.begin(),
726 search_inset, matchIT());
727 if (it != insetlist.end() && (*it).pos == pos)
730 lyxerr << "ERROR (LyXParagraph::GetInset): "
731 "Inset does not exist: " << pos << endl;
734 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
735 // Did this commenting out introduce a bug? So far I have not
736 // see any, please enlighten me. (Lgb)
737 // My guess is that since the inset does not exist, we might
738 // as well replace it with a space to prevent craches. (Asger)
743 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
748 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
749 return NextAfterFootnote()
750 ->GetInset(pos - text.size() - 1);
752 lyxerr << "ERROR (LyXParagraph::GetInset): "
753 "position does not exist: "
759 lyx::Assert(pos < size());
762 InsetTable search_inset(pos, 0);
763 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
765 search_inset, matchIT());
766 if (cit != insetlist.end() && (*cit).pos == pos)
769 lyxerr << "ERROR (LyXParagraph::GetInset): "
770 "Inset does not exist: " << pos << endl;
772 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
773 // Did this commenting out introduce a bug? So far I have not
774 // see any, please enlighten me. (Lgb)
775 // My guess is that since the inset does not exist, we might
776 // as well replace it with a space to prevent craches. (Asger)
781 // Gets uninstantiated font setting at position.
782 // Optimized after profiling. (Asger)
784 LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
785 LyXParagraph::size_type pos) const
788 FontTable search_font(pos, LyXFont());
789 FontList::const_iterator cit = lower_bound(fontlist.begin(),
791 search_font, matchFT());
792 if (cit != fontlist.end())
793 return (*cit).font();
795 // > because last is the next unused position, and you can
796 // use it if you want
797 else if (pos > size()) {
799 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
800 return NextAfterFootnote()
801 ->GetFontSettings(bparams,
802 pos - text.size() - 1);
804 // Why is it an error to ask for the font of a
805 // position that does not exist? Would it be
806 // enough for this to be enabled on debug?
807 // We want strict error checking, but it's ok to only
808 // have it when debugging. (Asger)
809 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
810 "position does not exist. "
811 << pos << " (" << static_cast<int>(pos)
813 } else if (pos > 0) {
814 return GetFontSettings(bparams, pos - 1);
817 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
820 LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
821 LyXParagraph::size_type pos) const
823 lyx::Assert(pos <= size());
824 FontTable search_font(pos, LyXFont());
825 FontList::const_iterator cit = lower_bound(fontlist.begin(),
827 search_font, matchFT());
828 if (cit != fontlist.end())
829 return (*cit).font();
831 if (pos == size() && size())
832 return GetFontSettings(bparams, pos - 1);
834 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
839 // Gets uninstantiated font setting at position 0
840 LyXFont const LyXParagraph::GetFirstFontSettings() const
843 if (!fontlist.empty())
844 return fontlist[0].font();
848 else if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
849 return NextAfterFootnote()->GetFirstFontSettings();
851 return LyXFont(LyXFont::ALL_INHERIT);
855 // Gets the fully instantiated font at a given position in a paragraph
856 // This is basically the same function as LyXText::GetFont() in text2.C.
857 // The difference is that this one is used for generating the LaTeX file,
858 // and thus cosmetic "improvements" are disallowed: This has to deliver
859 // the true picture of the buffer. (Asger)
860 // If position is -1, we get the layout font of the paragraph.
861 // If position is -2, we get the font of the manual label of the paragraph.
862 LyXFont const LyXParagraph::getFont(BufferParams const & bparams,
863 LyXParagraph::size_type pos) const
866 LyXLayout const & layout =
867 textclasslist.Style(bparams.textclass,
869 LyXParagraph::size_type main_body = 0;
870 if (layout.labeltype == LABEL_MANUAL)
871 main_body = BeginningOfMainBody();
876 layoutfont = layout.labelfont;
878 layoutfont = layout.font;
879 tmpfont = GetFontSettings(bparams, pos);
880 tmpfont.realize(layoutfont);
882 // process layoutfont for pos == -1 and labelfont for pos < -1
884 tmpfont = layout.font;
886 tmpfont = layout.labelfont;
887 tmpfont.setLanguage(getParLanguage(bparams));
890 // check for environment font information
891 char par_depth = GetDepth();
892 LyXParagraph const * par = this;
893 while (par && par_depth && !tmpfont.resolved()) {
894 par = par->DepthHook(par_depth - 1);
896 tmpfont.realize(textclasslist.
897 Style(bparams.textclass,
898 par->GetLayout()).font);
899 par_depth = par->GetDepth();
903 tmpfont.realize(textclasslist
904 .TextClass(bparams.textclass)
910 /// Returns the height of the highest font in range
912 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
913 LyXParagraph::size_type endpos) const
915 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
916 if (fontlist.empty())
919 FontTable end_search(endpos, LyXFont());
920 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
922 end_search, matchFT());
923 if (end_it != fontlist.end())
926 FontTable start_search(startpos, LyXFont());
927 for (FontList::const_iterator cit =
928 lower_bound(fontlist.begin(),
930 start_search, matchFT());
931 cit != end_it; ++cit) {
932 LyXFont::FONT_SIZE size = (*cit).font().size();
933 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
941 LyXParagraph::value_type
942 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
944 lyx::Assert(pos >= 0);
950 // > because last is the next unused position, and you can
951 // use it if you want
952 else if (pos > size()) {
953 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
954 return NextAfterFootnote()
955 ->GetChar(pos - text.size() - 1);
957 lyxerr << "ERROR (LyXParagraph::GetChar const): "
958 "position does not exist."
959 << pos << " (" << static_cast<int>(pos)
965 // We should have a footnote environment.
966 if (!next_ || next_->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
967 // Notice that LyX does request the
968 // last char from time to time. (Asger)
969 //lyxerr << "ERROR (LyXParagraph::GetChar): "
970 // "expected footnote." << endl;
973 switch (next_->footnotekind) {
974 case LyXParagraph::FOOTNOTE:
975 return LyXParagraph::META_FOOTNOTE;
976 case LyXParagraph::MARGIN:
977 return LyXParagraph::META_MARGIN;
978 case LyXParagraph::FIG:
979 case LyXParagraph::WIDE_FIG:
980 return LyXParagraph::META_FIG;
981 case LyXParagraph::TAB:
982 case LyXParagraph::WIDE_TAB:
983 return LyXParagraph::META_TAB;
984 case LyXParagraph::ALGORITHM:
985 return LyXParagraph::META_ALGORITHM;
987 return '\0'; // to shut up gcc
991 //LyXParagraph::value_type
992 //LyXParagraph::GetChar(LyXParagraph::size_type pos) const
994 // lyx::Assert(pos <= size());
995 // if (!size() || pos == size()) return '\0';
1002 LyXParagraph::value_type
1003 LyXParagraph::GetUChar(BufferParams const & bparams,
1004 LyXParagraph::size_type pos) const
1006 value_type c = GetChar(pos);
1007 if (!lyxrc.rtl_support)
1037 if (uc != c && GetFontSettings(bparams, pos).isRightToLeft())
1044 // return an string of the current word, and the end of the word in lastpos.
1045 string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1047 lyx::Assert(lastpos >= 0);
1049 // the current word is defined as starting at the first character
1050 // from the immediate left of lastpospos which meets the definition
1051 // of IsLetter(), continuing to the last character to the right
1052 // of this meeting IsLetter.
1058 // move back until we have a letter
1060 //there's no real reason to have firstpos & lastpos as
1061 //separate variables as this is written, but maybe someon
1062 // will want to return firstpos in the future.
1064 //since someone might have typed a punctuation first
1065 int firstpos = lastpos;
1067 while ((firstpos >= 0) && !IsLetter(firstpos))
1070 // now find the beginning by looking for a nonletter
1072 while ((firstpos>= 0) && IsLetter(firstpos))
1075 // the above is now pointing to the preceeding non-letter
1079 // so copy characters into theword until we get a nonletter
1080 // note that this can easily exceed lastpos, wich means
1081 // that if used in the middle of a word, the whole word
1084 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1091 LyXParagraph::size_type LyXParagraph::Last() const
1093 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1094 return text.size() + NextAfterFootnote()->Last() + 1;
1095 // the 1 is the symbol
1104 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1106 // > because last is the next unused position, and you can
1107 // use it if you want
1110 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1111 return NextAfterFootnote()
1112 ->ParFromPos(pos - text.size() - 1);
1114 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1115 "position does not exist." << endl;
1124 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1126 // > because last is the next unused position, and you can
1127 // use it if you want
1130 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1131 return NextAfterFootnote()
1132 ->PositionInParFromPos(pos - text.size() - 1);
1135 "ERROR (LyXParagraph::PositionInParFromPos): "
1136 "position does not exist." << endl;
1145 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1146 LyXFont const & font)
1149 // > because last is the next unused position, and you can
1150 // use it if you want
1153 next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1154 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1157 lyxerr << "ERROR (LyXParagraph::SetFont): "
1158 "position does not exist." << endl;
1163 lyx::Assert(pos <= size());
1166 // First, reduce font against layout/label font
1167 // Update: The SetCharFont() routine in text2.C already
1168 // reduces font, so we don't need to do that here. (Asger)
1169 // No need to simplify this because it will disappear
1170 // in a new kernel. (Asger)
1171 // Next search font table
1173 FontTable search_font(pos, LyXFont());
1174 FontList::iterator it = lower_bound(fontlist.begin(),
1176 search_font, matchFT());
1177 unsigned int i = it - fontlist.begin();
1178 bool notfound = it == fontlist.end();
1180 if (!notfound && fontlist[i].font() == font)
1183 bool begin = pos == 0 || notfound ||
1184 (i > 0 && fontlist[i-1].pos() == pos - 1);
1185 // Is position pos is a beginning of a font block?
1186 bool end = !notfound && fontlist[i].pos() == pos;
1187 // Is position pos is the end of a font block?
1188 if (begin && end) { // A single char block
1189 if (i + 1 < fontlist.size() &&
1190 fontlist[i + 1].font() == font) {
1191 // Merge the singleton block with the next block
1192 fontlist.erase(fontlist.begin() + i);
1193 if (i > 0 && fontlist[i - 1].font() == font)
1194 fontlist.erase(fontlist.begin() + i-1);
1195 } else if (i > 0 && fontlist[i - 1].font() == font) {
1196 // Merge the singleton block with the previous block
1197 fontlist[i - 1].pos(pos);
1198 fontlist.erase(fontlist.begin() + i);
1200 fontlist[i].font(font);
1202 if (i > 0 && fontlist[i - 1].font() == font)
1203 fontlist[i - 1].pos(pos);
1205 fontlist.insert(fontlist.begin() + i,
1206 FontTable(pos, font));
1208 fontlist[i].pos(pos - 1);
1209 if (!(i + 1 < fontlist.size() &&
1210 fontlist[i + 1].font() == font))
1211 fontlist.insert(fontlist.begin() + i + 1,
1212 FontTable(pos, font));
1213 } else { // The general case. The block is splitted into 3 blocks
1214 fontlist.insert(fontlist.begin() + i,
1215 FontTable(pos - 1, fontlist[i].font()));
1216 fontlist.insert(fontlist.begin() + i + 1,
1217 FontTable(pos, font));
1223 void LyXParagraph::next(LyXParagraph * p)
1229 // This function is able to hide closed footnotes.
1230 LyXParagraph * LyXParagraph::next()
1233 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1234 LyXParagraph * tmp = next_;
1236 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1238 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1239 return tmp->next(); /* there can be more than one
1240 footnote in a logical
1243 return next_; // This should never happen!
1250 LyXParagraph const * LyXParagraph::next() const
1253 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1254 LyXParagraph * tmp = next_;
1256 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1258 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1259 return tmp->next(); /* there can be more than one
1260 footnote in a logical
1263 return next_; // This should never happen!
1271 LyXParagraph * LyXParagraph::NextAfterFootnote()
1273 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1274 LyXParagraph * tmp = next_;
1275 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1277 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1278 return tmp; /* there can be more than one footnote
1279 in a logical paragraph */
1281 return next_; // This should never happen!
1289 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1291 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1292 LyXParagraph * tmp = next_;
1293 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1295 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1296 return tmp; /* there can be more than one footnote
1297 in a logical paragraph */
1299 return next_; // This should never happen!
1307 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1310 if (previous_ && previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1312 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1313 tmp = tmp->previous_;
1314 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1315 return tmp; /* there can be more than one footnote
1316 in a logical paragraph */
1318 return previous_; // This should never happen!
1326 LyXParagraph * LyXParagraph::LastPhysicalPar()
1328 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1331 LyXParagraph * tmp = this;
1333 && tmp->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1334 tmp = tmp->NextAfterFootnote();
1342 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1344 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1347 LyXParagraph const * tmp = this;
1349 && tmp->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1350 tmp = tmp->NextAfterFootnote();
1358 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1362 LyXParagraph * tmppar = this;
1366 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1367 tmppar = tmppar->previous_;
1378 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1382 LyXParagraph const * tmppar = this;
1386 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1387 tmppar = tmppar->previous_;
1397 void LyXParagraph::previous(LyXParagraph * p)
1403 // This function is able to hide closed footnotes.
1404 LyXParagraph * LyXParagraph::previous()
1407 LyXParagraph * tmp = previous_;
1412 && tmp->previous_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1413 tmp = tmp->previous_;
1415 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1416 tmp = tmp->previous_;
1417 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1418 return tmp->next_->previous();
1428 // This function is able to hide closed footnotes.
1429 LyXParagraph const * LyXParagraph::previous() const
1432 LyXParagraph * tmp = previous_;
1436 && tmp->previous_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1437 tmp = tmp->previous_;
1439 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1440 tmp = tmp->previous_;
1441 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1442 return tmp->next_->previous();
1453 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1454 LyXParagraph::size_type pos,
1459 // create a new paragraph
1461 size_type pos_first;
1462 LyXParagraph * par = ParFromPos(pos);
1463 LyXParagraph * firstpar = FirstPhysicalPar();
1465 LyXParagraph * tmp = new LyXParagraph(par);
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
1473 // layout stays the same with latex-environments
1475 tmp->SetOnlyLayout(bparams, firstpar->layout);
1476 tmp->SetLabelWidthString(firstpar->params.labelWidthString());
1479 if (Last() > pos || !Last() || flag == 2) {
1480 tmp->SetOnlyLayout(bparams, firstpar->layout);
1481 tmp->params.align(firstpar->params.align());
1482 tmp->SetLabelWidthString(firstpar->params.labelWidthString());
1484 tmp->params.lineBottom(firstpar->params.lineBottom());
1485 firstpar->params.lineBottom(false);
1486 tmp->params.pagebreakBottom(firstpar->params.pagebreakBottom());
1487 firstpar->params.pagebreakBottom(false);
1488 tmp->params.spaceBottom(firstpar->params.spaceBottom());
1489 firstpar->params.spaceBottom(VSpace(VSpace::NONE));
1491 tmp->params.depth(firstpar->params.depth());
1492 tmp->params.noindent(firstpar->params.noindent());
1494 // copy everything behind the break-position
1495 // to the new paragraph
1497 while (ParFromPos(pos_first) != par)
1499 pos_end = pos_first + par->text.size() - 1;
1502 for (i = j = pos; i <= pos_end; ++i) {
1503 par->CutIntoMinibuffer(bparams, i - pos_first);
1504 if (tmp->InsertFromMinibuffer(j - pos))
1510 for (i = pos_end; i >= pos; --i)
1511 par->Erase(i - pos_first);
1516 // just an idea of me
1518 tmp->params.lineTop(firstpar->params.lineTop());
1519 tmp->params.pagebreakTop(firstpar->params.pagebreakTop());
1520 tmp->params.spaceTop(firstpar->params.spaceTop());
1521 tmp->bibkey = firstpar->bibkey;
1523 // layout stays the same with latex-environments
1525 firstpar->SetOnlyLayout(bparams, tmp->layout);
1526 firstpar->SetLabelWidthString(tmp->params.labelWidthString());
1527 firstpar->params.depth(tmp->params.depth());
1532 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1533 LyXParagraph::size_type pos,
1536 // create a new paragraph
1537 LyXParagraph * tmp = new LyXParagraph(this);
1539 // this is an idea for a more userfriendly layout handling, I will
1540 // see what the users say
1542 // layout stays the same with latex-environments
1544 tmp->SetOnlyLayout(layout);
1545 tmp->SetLabelWidthString(params.labelWidthString());
1548 if (size() > pos || !size() || flag == 2) {
1549 tmp->SetOnlyLayout(layout);
1550 tmp->params.align(params.align());
1551 tmp->SetLabelWidthString(params.labelWidthString());
1553 tmp->params.lineBottom(params.lineBottom());
1554 params.lineBottom(false);
1555 tmp->params.pagebreakBottom(params.pagebreakBottom());
1556 params.pagebreakBottom(false);
1557 tmp->params.spaceBottom(params.spaceBottom());
1558 params.spaceBottom(VSpace(VSpace::NONE));
1560 tmp->params.depth(params.depth());
1561 tmp->params.noindent(params.noindent());
1563 // copy everything behind the break-position
1564 // to the new paragraph
1565 size_type pos_end = text.size() - 1;
1568 for (; i <= pos_end; ++i) {
1569 CutIntoMinibuffer(bparams, i);
1570 if (tmp->InsertFromMinibuffer(j - pos))
1574 for (i = pos_end; i >= pos; --i)
1580 // just an idea of me
1582 tmp->params.lineTop(params.lineTop());
1583 tmp->params.pagebreakTop(params.pagebreakTop());
1584 tmp->params.spaceTop(params.spaceTop());
1585 tmp->bibkey = bibkey;
1587 // layout stays the same with latex-environments
1589 SetOnlyLayout(tmp->layout);
1590 SetLabelWidthString(tmp->params.labelWidthString());
1591 params.depth(tmp->params.depth());
1598 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1601 par = par->FirstPhysicalPar();
1602 footnoteflag = par->footnoteflag;
1603 footnotekind = par->footnotekind;
1605 layout = par->layout;
1606 params.makeSame(par->params);
1608 // This can be changed after NEW_INSETS is in effect. (Lgb)
1609 SetLabelWidthString(par->params.labelWidthString());
1614 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1616 LyXParagraph * tmppar = this;
1619 && tmppar->previous_->footnoteflag ==
1620 LyXParagraph::CLOSED_FOOTNOTE)
1621 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1622 tmppar = tmppar->previous_;
1625 return this; // This should never happen!
1632 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1634 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1644 && (IsNewline(0) || IsLineSeparator(0))){
1655 LyXParagraph * LyXParagraph::Clone() const
1657 // create a new paragraph
1658 LyXParagraph * result = new LyXParagraph;
1660 result->MakeSameLayout(this);
1662 // this is because of the dummy layout of the paragraphs that
1664 result->layout = layout;
1666 result->inset_owner = inset_owner;
1670 result->bibkey = static_cast<InsetBibKey *>
1671 (bibkey->Clone(*current_view->buffer()));
1675 // copy everything behind the break-position to the new paragraph
1677 result->text = text;
1678 result->fontlist = fontlist;
1679 result->insetlist = insetlist;
1680 for (InsetList::iterator it = result->insetlist.begin();
1681 it != result->insetlist.end(); ++it)
1682 (*it).inset = (*it).inset->Clone(*current_view->buffer());
1687 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1690 par = par->FirstPhysicalPar();
1695 par->footnoteflag == footnoteflag &&
1696 par->footnotekind == footnotekind &&
1698 par->layout == layout &&
1699 params.sameLayout(par->params);
1703 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1704 LyXParagraph::size_type pos)
1707 // create a new paragraph
1708 LyXParagraph * par = ParFromPos(pos);
1710 LyXParagraph * tmp = new LyXParagraph(par);
1712 tmp->MakeSameLayout(par);
1714 // When can pos < Last()?
1715 // I guess pos == Last() is possible.
1717 // copy everything behind the break-position to the new
1719 size_type pos_first = 0;
1720 while (ParFromPos(pos_first) != par)
1722 size_type pos_end = pos_first + par->text.size() - 1;
1725 for (i = j = pos; i <= pos_end; ++i) {
1726 par->CutIntoMinibuffer(bparams, i - pos_first);
1727 if (tmp->InsertFromMinibuffer(j - pos))
1733 for (size_type i = pos_end; i >= pos; --i)
1734 par->Erase(i - pos_first);
1739 // create a new paragraph
1740 LyXParagraph * tmp = new LyXParagraph(this);
1741 tmp->MakeSameLayout(this);
1743 // When can pos > Last()?
1744 // I guess pos == Last() is possible.
1746 // copy everything behind the break-position to the new
1748 size_type pos_end = text.size() - 1;
1751 for (i = j = pos; i <= pos_end; ++i) {
1752 CutIntoMinibuffer(bparams, i);
1753 if (tmp->InsertFromMinibuffer(j - pos))
1759 for (size_type i = pos_end; i >= pos; --i)
1768 // Be carefull, this does not make any check at all.
1769 // This method has wrong name, it combined this par with the next par.
1770 // In that sense it is the reverse of break paragraph. (Lgb)
1771 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1773 // copy the next paragraph to this one
1774 LyXParagraph * the_next = next();
1776 // first the DTP-stuff
1778 LyXParagraph * firstpar = FirstPhysicalPar();
1779 firstpar->params.lineBottom(the_next->params.lineBottom());
1780 firstpar->params.spaceBottom(the_next->params.spaceBottom());
1781 firstpar->params.pagebreakBottom(the_next->params.pagebreakBottom());
1783 size_type pos_end = the_next->text.size() - 1;
1784 size_type pos_insert = Last();
1786 params.lineBottom(the_next->params.lineBottom());
1787 params.spaceBottom(the_next->params.spaceBottom());
1788 params.pagebreakBottom(the_next->params.pagebreakBottom());
1790 size_type pos_end = the_next->text.size() - 1;
1791 size_type pos_insert = size();
1794 // ok, now copy the paragraph
1796 for (i = j = 0; i <= pos_end; ++i) {
1797 the_next->CutIntoMinibuffer(bparams, i);
1798 if (InsertFromMinibuffer(pos_insert + j))
1802 // delete the next paragraph
1803 LyXParagraph * ppar = the_next->previous_;
1804 LyXParagraph * npar = the_next->next_;
1811 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1813 LyXParagraph * par = ParFromPos(pos);
1815 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1816 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1822 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1824 LyXParagraph * par = ParFromPos(pos);
1826 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1827 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1834 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1836 LyXParagraph const * par = this;
1837 int par_depth = GetDepth();
1839 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1840 int const endlabeltype =
1841 textclasslist.Style(bparams.textclass,
1842 layout).endlabeltype;
1843 if (endlabeltype != END_LABEL_NO_LABEL) {
1844 LyXParagraph const * last = this;
1846 if (footnoteflag == NO_FOOTNOTE)
1847 last = LastPhysicalPar();
1848 else if (next_->footnoteflag == NO_FOOTNOTE)
1849 return endlabeltype;
1854 if (!last || !last->next_)
1855 return endlabeltype;
1857 int next_depth = last->next_->GetDepth();
1858 if (par_depth > next_depth ||
1859 (par_depth == next_depth && layout != last->next_->GetLayout() ))
1860 return endlabeltype;
1865 par = par->DepthHook(par_depth - 1);
1867 par_depth = par->GetDepth();
1869 return END_LABEL_NO_LABEL;
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);
1941 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1942 LyXTextClass::size_type new_layout)
1944 LyXParagraph * par = FirstPhysicalPar();
1945 LyXParagraph * ppar = 0;
1946 LyXParagraph * npar = 0;
1948 par->layout = new_layout;
1950 if (par->params.pextraType() == PEXTRA_NONE) {
1951 if (par->previous()) {
1952 ppar = par->previous()->FirstPhysicalPar();
1955 && (ppar->params.depth() > par->params.depth()))
1956 ppar = ppar->previous()->FirstPhysicalPar();
1959 npar = par->next()->NextAfterFootnote();
1962 && (npar->params.depth() > par->params.depth()))
1963 npar = npar->next()->NextAfterFootnote();
1965 if (ppar && (ppar->params.pextraType() != PEXTRA_NONE)) {
1966 string p1 = ppar->params.pextraWidth();
1967 string p2 = ppar->params.pextraWidthp();
1968 ppar->SetPExtraType(bparams,
1969 ppar->params.pextraType(),
1972 if ((par->params.pextraType() == PEXTRA_NONE) &&
1973 npar && (npar->params.pextraType() != PEXTRA_NONE)) {
1974 string const p1 = npar->params.pextraWidth();
1975 string const p2 = npar->params.pextraWidthp();
1976 npar->SetPExtraType(bparams, npar->params.pextraType(),
1982 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1984 layout = new_layout;
1990 void LyXParagraph::SetLayout(BufferParams const & bparams,
1991 LyXTextClass::size_type new_layout)
1994 * par = FirstPhysicalPar(),
1998 par->layout = new_layout;
1999 par->params.labelWidthString(string());
2000 par->params.align(LYX_ALIGN_LAYOUT);
2001 par->params.spaceTop(VSpace(VSpace::NONE));
2002 par->params.spaceBottom(VSpace(VSpace::NONE));
2003 par->params.spacing(Spacing(Spacing::Default));
2005 if (par->params.pextraType() == PEXTRA_NONE) {
2006 if (par->previous()) {
2007 ppar = par->previous()->FirstPhysicalPar();
2010 && (ppar->params.depth() > par->params.depth()))
2011 ppar = ppar->previous()->FirstPhysicalPar();
2014 npar = par->next()->NextAfterFootnote();
2017 && (npar->params.depth() > par->params.depth()))
2018 npar = npar->next()->NextAfterFootnote();
2020 if (ppar && (ppar->params.pextraType() != PEXTRA_NONE)) {
2021 string const p1 = ppar->params.pextraWidth();
2022 string const p2 = ppar->params.pextraWidthp();
2023 ppar->SetPExtraType(bparams, ppar->params.pextraType(),
2026 if ((par->params.pextraType() == PEXTRA_NONE) &&
2027 npar && (npar->params.pextraType() != PEXTRA_NONE)) {
2028 string const p1 = npar->params.pextraWidth();
2029 string const p2 = npar->params.pextraWidthp();
2030 npar->SetPExtraType(bparams, npar->params.pextraType(),
2036 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
2038 layout = new_layout;
2039 params.labelWidthString(string());
2040 params.align(LYX_ALIGN_LAYOUT);
2041 params.spaceTop(VSpace(VSpace::NONE));
2042 params.spaceBottom(VSpace(VSpace::NONE));
2043 params.spacing(Spacing(Spacing::Default));
2048 // if the layout of a paragraph contains a manual label, the beginning of the
2049 // main body is the beginning of the second word. This is what the par-
2050 // function returns. If the layout does not contain a label, the main
2051 // body always starts with position 0. This differentiation is necessary,
2052 // because there cannot be a newline or a blank <= the beginning of the
2053 // main body in TeX.
2055 int LyXParagraph::BeginningOfMainBody() const
2058 if (FirstPhysicalPar() != this)
2061 // Unroll the first two cycles of the loop
2062 // and remember the previous character to
2063 // remove unnecessary GetChar() calls
2066 && GetChar(i) != LyXParagraph::META_NEWLINE
2069 char previous_char = 0;
2072 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2073 // Yes, this ^ is supposed to be "= " not "=="
2076 && previous_char != ' '
2077 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2079 previous_char = temp;
2085 if (i == 0 && i == size() &&
2086 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2087 && next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2088 ++i; /* the cursor should not jump
2089 * to the main body if there
2096 LyXParagraph * LyXParagraph::DepthHook(int deth)
2098 LyXParagraph * newpar = this;
2104 newpar = newpar->FirstPhysicalPar()->previous();
2106 newpar = newpar->previous();
2108 } while (newpar && newpar->GetDepth() > deth
2110 && newpar->footnoteflag == footnoteflag
2115 if (previous() || GetDepth())
2116 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2121 return newpar->FirstPhysicalPar();
2128 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2130 LyXParagraph const * newpar = this;
2136 newpar = newpar->FirstPhysicalPar()->previous();
2138 newpar = newpar->previous();
2140 } while (newpar && newpar->GetDepth() > deth
2142 && newpar->footnoteflag == footnoteflag
2147 if (previous() || GetDepth())
2148 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2153 return newpar->FirstPhysicalPar();
2160 int LyXParagraph::AutoDeleteInsets()
2163 InsetList::size_type index = 0;
2164 while (index < insetlist.size()) {
2165 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2166 Erase(insetlist[index].pos);
2167 // Erase() calls to insetlist.erase(&insetlist[index])
2168 // so index shouldn't be increased.
2177 LyXParagraph::inset_iterator
2178 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2180 InsetTable search_inset(pos, 0);
2181 InsetList::iterator it = lower_bound(insetlist.begin(),
2183 search_inset, matchIT());
2184 return inset_iterator(it);
2188 // returns -1 if inset not found
2189 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2192 for (InsetList::const_iterator cit = insetlist.begin();
2193 cit != insetlist.end(); ++cit) {
2194 if ((*cit).inset == inset) {
2198 if (inset == bibkey)
2202 // Think about footnotes.
2203 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2204 && next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2206 NextAfterFootnote()->GetPositionOfInset(inset);
2208 return text.size() + 1 + further;
2215 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2216 BufferParams const & bparams,
2217 ostream & os, TexRow & texrow,
2222 TexRow & foot_texrow,
2227 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2228 LyXLayout const & style =
2229 textclasslist.Style(bparams.textclass,
2232 bool further_blank_line = false;
2235 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2238 if (params.startOfAppendix()) {
2239 os << "\\appendix\n";
2243 if (!params.spacing().isDefault()
2244 && (!previous() || !previous()->HasSameLayout(this))) {
2245 os << params.spacing().writeEnvirBegin() << "\n";
2249 if (tex_code_break_column && style.isCommand()){
2254 if (params.pagebreakTop()) {
2256 further_blank_line = true;
2258 if (params.spaceTop().kind() != VSpace::NONE) {
2259 os << params.spaceTop().asLatexCommand(bparams);
2260 further_blank_line = true;
2263 if (params.lineTop()) {
2264 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2265 << "\\vspace{-1\\parskip}";
2266 further_blank_line = true;
2269 if (further_blank_line){
2274 Language const * language = getParLanguage(bparams);
2275 Language const * doc_language = bparams.language;
2276 Language const * previous_language = previous_
2277 ? previous_->getParLanguage(bparams) : doc_language;
2278 if (language->babel() != doc_language->babel() &&
2279 language->babel() != previous_language->babel()) {
2280 os << subst(lyxrc.language_command_begin, "$$lang",
2286 if (bparams.inputenc == "auto" &&
2287 language->encoding() != previous_language->encoding()) {
2288 os << "\\inputencoding{"
2289 << language->encoding()->LatexName()
2294 switch (style.latextype) {
2297 << style.latexname()
2298 << style.latexparam();
2300 case LATEX_ITEM_ENVIRONMENT:
2302 bibkey->Latex(buf, os, false, false);
2306 case LATEX_LIST_ENVIRONMENT:
2313 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2315 LyXParagraph * par = next_;
2317 // Spit out footnotes
2318 if (lyxrc.rtl_support) {
2319 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
2320 && next_->footnoteflag != footnoteflag) {
2321 LyXParagraph * p = 0;
2322 bool is_rtl = (size() > 0)
2323 ? GetFontSettings(bparams,
2324 size()-1).isRightToLeft()
2325 : language->RightToLeft();
2326 if ((p = NextAfterFootnote()) != 0 &&
2328 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2329 is_rtl = getParLanguage(bparams)->RightToLeft();
2330 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2331 && par->footnoteflag != footnoteflag) {
2332 par = par->TeXFootnote(buf, bparams,
2334 foot_texrow, foot_count,
2336 par->SimpleTeXOnePar(buf, bparams,
2337 os, texrow, moving_arg);
2338 is_rtl = (par->size() > 0)
2339 ? par->GetFontSettings(bparams,
2340 par->size()-1).isRightToLeft()
2341 : language->RightToLeft();
2343 par->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2344 (p = par->NextAfterFootnote()) != 0 &&
2346 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2347 is_rtl = language->RightToLeft();
2352 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2353 && par->footnoteflag != footnoteflag) {
2354 par = par->TeXFootnote(buf, bparams,
2356 foot, foot_texrow, foot_count,
2358 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2364 // Make sure that \\par is done with the font of the last
2365 // character if this has another size as the default.
2366 // This is necessary because LaTeX (and LyX on the screen)
2367 // calculates the space between the baselines according
2368 // to this font. (Matthias)
2370 // Is this really needed ? (Dekel)
2371 // We do not need to use to change the font for the last paragraph
2372 // or for a command.
2374 LyXFont font = getFont(bparams, Last() - 1);
2376 LyXFont font = getFont(bparams, size() - 1);
2378 bool is_command = textclasslist.Style(bparams.textclass,
2379 GetLayout()).isCommand();
2380 if (style.resfont.size() != font.size() && next_ && !is_command) {
2383 os << "\\" << font.latexSize() << " \\par}";
2384 } else if (need_par) {
2386 } else if (is_command)
2389 if (language->babel() != doc_language->babel() &&
2392 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2394 || par->getParLanguage(bparams)->babel() != language->babel())) {
2396 << subst(lyxrc.language_command_end, "$$lang",
2397 doc_language->babel());
2400 switch (style.latextype) {
2401 case LATEX_ITEM_ENVIRONMENT:
2402 case LATEX_LIST_ENVIRONMENT:
2403 if (par && (params.depth() < par->params.depth())) {
2408 case LATEX_ENVIRONMENT:
2409 // if its the last paragraph of the current environment
2410 // skip it otherwise fall through
2412 && (par->layout != layout
2413 || par->params.depth() != params.depth()
2415 || par->params.pextraType() != params.pextraType()
2420 // we don't need it for the last paragraph!!!
2421 // or for tables in floats
2422 // -- effectively creates a \par where there isn't one which
2423 // breaks a \subfigure or \subtable.
2425 // && footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2431 further_blank_line = false;
2432 if (params.lineBottom()) {
2434 os << "\\lyxline{\\" << getFont(bparams,
2435 Last() - 1).latexSize() << '}';
2437 os << "\\lyxline{\\" << getFont(bparams,
2438 size() - 1).latexSize() << '}';
2440 further_blank_line = true;
2443 if (params.spaceBottom().kind() != VSpace::NONE) {
2444 os << params.spaceBottom().asLatexCommand(bparams);
2445 further_blank_line = true;
2448 if (params.pagebreakBottom()) {
2450 further_blank_line = true;
2453 if (further_blank_line){
2458 if (!params.spacing().isDefault()
2459 && (!par || !par->HasSameLayout(this))) {
2460 os << params.spacing().writeEnvirEnd() << "\n";
2464 // we don't need it for the last paragraph!!!
2467 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2468 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2475 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2480 // This one spits out the text of the paragraph
2481 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2482 BufferParams const & bparams,
2483 ostream & os, TexRow & texrow,
2486 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2488 bool return_value = false;
2490 LyXLayout const & style =
2491 textclasslist.Style(bparams.textclass,
2493 LyXFont basefont, last_font;
2495 // Maybe we have to create a optional argument.
2496 size_type main_body;
2497 if (style.labeltype != LABEL_MANUAL)
2500 main_body = BeginningOfMainBody();
2502 if (main_body > 0) {
2504 basefont = getFont(bparams, -2); // Get label font
2506 basefont = getFont(bparams, -1); // Get layout font
2517 if (style.isCommand()) {
2520 } else if (params.align() != LYX_ALIGN_LAYOUT) {
2523 return_value = true;
2527 moving_arg |= style.needprotect;
2529 // Which font is currently active?
2530 LyXFont running_font(basefont);
2531 // Do we have an open font change?
2532 bool open_font = false;
2534 texrow.start(this, 0);
2536 for (size_type i = 0; i < size(); ++i) {
2538 // First char in paragraph or after label?
2544 if (main_body > 0) {
2546 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2549 basefont = getFont(bparams, -1); // Now use the layout font
2550 running_font = basefont;
2554 if (style.isCommand()) {
2557 } else if (params.align() != LYX_ALIGN_LAYOUT && next_) {
2558 // We do not need \par here (Dekel)
2562 return_value = true;
2565 if (params.noindent()) {
2566 os << "\\noindent ";
2569 switch (params.align()) {
2570 case LYX_ALIGN_NONE:
2571 case LYX_ALIGN_BLOCK:
2572 case LYX_ALIGN_LAYOUT:
2573 case LYX_ALIGN_SPECIAL:
2575 case LYX_ALIGN_LEFT:
2578 if (getParLanguage(bparams)->babel() != "hebrew") {
2579 os << "\\raggedright ";
2582 os << "\\raggedleft ";
2586 case LYX_ALIGN_RIGHT:
2589 if (getParLanguage(bparams)->babel() != "hebrew") {
2590 os << "\\raggedleft ";
2593 os << "\\raggedright ";
2597 case LYX_ALIGN_CENTER:
2600 os << "\\centering ";
2606 value_type c = GetChar(i);
2608 // Fully instantiated font
2609 LyXFont font = getFont(bparams, i);
2611 LyXParagraph * p = 0;
2614 previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2615 (p = PreviousBeforeFootnote()) != 0)
2616 last_font = p->getFont(bparams, p->size() - 1);
2619 last_font = running_font;
2621 // Spaces at end of font change are simulated to be
2622 // outside font change, i.e. we write "\textXX{text} "
2623 // rather than "\textXX{text }". (Asger)
2624 if (open_font && c == ' ' && i <= size() - 2
2625 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2626 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2627 font = getFont(bparams, i + 1);
2629 // We end font definition before blanks
2630 if (!font.equalExceptLatex(running_font) && open_font) {
2631 column += running_font.latexWriteEndChanges(os,
2633 (i == main_body-1) ? basefont : font);
2634 running_font = basefont;
2638 // Blanks are printed before start of fontswitch
2640 // Do not print the separation of the optional argument
2641 if (i != main_body - 1) {
2642 SimpleTeXBlanks(os, texrow, i,
2643 column, font, style);
2647 // Do we need to change font?
2648 if (!font.equalExceptLatex(running_font)
2649 && i != main_body-1) {
2650 column += font.latexWriteStartChanges(os, basefont,
2652 running_font = font;
2656 if (c == LyXParagraph::META_NEWLINE) {
2657 // newlines are handled differently here than
2658 // the default in SimpleTeXSpecialChars().
2659 if (!style.newline_allowed
2660 || font.latex() == LyXFont::ON) {
2664 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2667 basefont = getFont(bparams, -1);
2668 running_font = basefont;
2669 if (font.family() ==
2670 LyXFont::TYPEWRITER_FAMILY) {
2678 texrow.start(this, i + 1);
2681 SimpleTeXSpecialChars(buf, bparams,
2682 os, texrow, moving_arg,
2683 font, running_font, basefont,
2684 open_font, style, i, column, c);
2688 // If we have an open font definition, we have to close it
2690 LyXParagraph * p = 0;
2693 && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
2694 && (p = NextAfterFootnote()) != 0
2699 running_font.latexWriteEndChanges(os, basefont,
2700 p->getFont(bparams, 0));
2702 running_font.latexWriteEndChanges(os, basefont, basefont);
2705 // Needed if there is an optional argument but no contents.
2706 if (main_body > 0 && main_body == size()) {
2708 return_value = false;
2711 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2712 return return_value;
2716 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2718 bool retval = false;
2720 case LyXParagraph::META_HFILL:
2721 sgml_string.erase();
2723 case LyXParagraph::META_NEWLINE:
2727 sgml_string = "&";
2730 sgml_string = "<";
2733 sgml_string = ">";
2736 sgml_string = "$";
2739 sgml_string = "#";
2742 sgml_string = "%";
2745 sgml_string = "[";
2748 sgml_string = "]";
2751 sgml_string = "{";
2754 sgml_string = "}";
2757 sgml_string = "˜";
2760 sgml_string = """;
2763 sgml_string = "\";
2769 case '\0': // Ignore :-)
2770 sgml_string.erase();
2780 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
2781 LyXParagraph::size_type const i,
2782 int & column, LyXFont const & font,
2783 LyXLayout const & style)
2785 if (column > tex_code_break_column
2787 && GetChar(i - 1) != ' '
2789 // In LaTeX mode, we don't want to
2790 // break lines since some commands
2792 && ! (font.latex() == LyXFont::ON)
2793 // same in FreeSpacing mode
2794 && !style.free_spacing
2795 // In typewriter mode, we want to avoid
2796 // ! . ? : at the end of a line
2797 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
2798 && (GetChar(i-1) == '.'
2799 || GetChar(i-1) == '?'
2800 || GetChar(i-1) == ':'
2801 || GetChar(i-1) == '!'))) {
2802 if (tex_code_break_column == 0) {
2803 // in batchmode we need LaTeX to still
2804 // see it as a space not as an extra '\n'
2810 texrow.start(this, i + 1);
2812 } else if (font.latex() == LyXFont::OFF) {
2813 if (style.free_spacing) {
2822 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
2823 BufferParams const & bparams,
2824 ostream & os, TexRow & texrow,
2827 LyXFont & running_font,
2830 LyXLayout const & style,
2831 LyXParagraph::size_type & i,
2833 LyXParagraph::value_type const c)
2835 // Two major modes: LaTeX or plain
2836 // Handle here those cases common to both modes
2837 // and then split to handle the two modes separately.
2839 case LyXParagraph::META_INSET: {
2840 Inset * inset = GetInset(i);
2843 int const len = os.tellp();
2844 //ostream::pos_type const len = os.tellp();
2845 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
2846 || inset->LyxCode() == Inset::MATH_CODE
2847 || inset->LyxCode() == Inset::URL_CODE)
2848 && running_font.isRightToLeft()) {
2853 int tmp = inset->Latex(buf, os, moving_arg,
2854 style.free_spacing);
2862 column += int(os.tellp()) - len;
2871 case LyXParagraph::META_NEWLINE:
2873 column += running_font.latexWriteEndChanges(os,
2878 basefont = getFont(bparams, -1);
2879 running_font = basefont;
2882 case LyXParagraph::META_HFILL:
2888 // And now for the special cases within each mode
2889 // Are we in LaTeX mode?
2890 if (font.latex() == LyXFont::ON) {
2891 // at present we only have one option
2892 // but I'll leave it as a switch statement
2893 // so its simpler to extend. (ARRae)
2896 // make sure that we will not print
2897 // error generating chars to the tex
2898 // file. This test would not be needed
2899 // if it were done in the buffer
2907 // Plain mode (i.e. not LaTeX)
2910 os << "\\textbackslash{}";
2914 case '°': case '±': case '²': case '³':
2915 case '×': case '÷': case '¹': case 'ª':
2916 case 'º': case '¬': case 'µ':
2917 if (bparams.inputenc == "latin1" ||
2918 (bparams.inputenc == "auto" &&
2919 font.language()->encoding()->LatexName()
2921 os << "\\ensuremath{"
2930 case '|': case '<': case '>':
2931 // In T1 encoding, these characters exist
2932 if (lyxrc.fontenc == "T1") {
2934 //... but we should avoid ligatures
2935 if ((c == '>' || c == '<')
2937 && GetChar(i + 1) == c) {
2938 //os << "\\textcompwordmark{}";
2939 // Jean-Marc, have a look at
2940 // this. IÂ think this works
2948 // Typewriter font also has them
2949 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
2953 // Otherwise, we use what LaTeX
2957 os << "\\textless{}";
2961 os << "\\textgreater{}";
2965 os << "\\textbar{}";
2971 case '-': // "--" in Typewriter mode -> "-{}-"
2973 && GetChar(i + 1) == '-'
2974 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
2983 os << "\\char`\\\"{}";
2988 if (bparams.inputenc == "default") {
2997 case '%': case '#': case '{':
3004 os << "\\textasciitilde{}";
3009 os << "\\textasciicircum{}";
3013 case '*': case '[': case ']':
3014 // avoid being mistaken for optional arguments
3015 os << '{' << c << '}';
3020 // Blanks are printed before font switching.
3021 // Sure? I am not! (try nice-latex)
3022 // I am sure it's correct. LyX might be smarter
3023 // in the future, but for now, nothing wrong is
3028 /* idea for labels --- begin*/
3032 && font.family() != LyXFont::TYPEWRITER_FAMILY
3033 && GetChar(i + 1) == 'y'
3034 && GetChar(i + 2) == 'X') {
3042 && font.family() != LyXFont::TYPEWRITER_FAMILY
3043 && GetChar(i + 1) == 'e'
3044 && GetChar(i + 2) == 'X') {
3049 // Check for "LaTeX2e"
3052 && font.family() != LyXFont::TYPEWRITER_FAMILY
3053 && GetChar(i + 1) == 'a'
3054 && GetChar(i + 2) == 'T'
3055 && GetChar(i + 3) == 'e'
3056 && GetChar(i + 4) == 'X'
3057 && GetChar(i + 5) == '2'
3058 && GetChar(i + 6) == 'e') {
3063 // Check for "LaTeX"
3066 && font.family() != LyXFont::TYPEWRITER_FAMILY
3067 && GetChar(i + 1) == 'a'
3068 && GetChar(i + 2) == 'T'
3069 && GetChar(i + 3) == 'e'
3070 && GetChar(i + 4) == 'X') {
3074 /* idea for labels --- end*/
3075 } else if (c != '\0') {
3085 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3086 BufferParams const & bparams,
3087 ostream & os, TexRow & texrow
3090 TexRow & foot_texrow,
3095 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3096 LyXParagraph * par = this;
3099 (par->params.depth() == params.depth())
3101 && (par->footnoteflag == footnoteflag)
3106 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3108 if (textclasslist.Style(bparams.textclass,
3109 par->layout).isEnvironment()
3111 || par->params.pextraType() != PEXTRA_NONE
3114 par = par->TeXEnvironment(buf, bparams,
3122 par = par->TeXOnePar(buf, bparams,
3132 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3138 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3139 BufferParams const & bparams,
3140 ostream & os, TexRow & texrow
3143 TexRow & foot_texrow,
3149 bool eindent_open = false;
3152 bool foot_this_level = false;
3155 // flags when footnotetext should be appended to file.
3156 static bool minipage_open = false;
3157 static int minipage_open_depth = 0;
3158 char par_sep = bparams.paragraph_separation;
3161 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3164 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3167 LyXLayout const & style =
3168 textclasslist.Style(bparams.textclass,
3172 if (params.pextraType() == PEXTRA_INDENT) {
3173 if (!params.pextraWidth().empty()) {
3174 os << "\\begin{LyXParagraphIndent}{"
3175 << params.pextraWidth() << "}\n";
3177 //float ib = atof(pextra_widthp.c_str())/100;
3178 // string can't handle floats at present (971109)
3179 // so I'll do a conversion by hand knowing that
3180 // the limits are 0.0 to 1.0. ARRae.
3181 os << "\\begin{LyXParagraphIndent}{";
3182 switch (params.pextraWidthp().length()) {
3188 << params.pextraWidthp();
3192 << params.pextraWidthp();
3194 os << "\\columnwidth}\n";
3197 eindent_open = true;
3199 if ((params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
3200 if (params.pextraHfill() && previous() &&
3201 (previous()->params.pextraType() == PEXTRA_MINIPAGE)) {
3202 os << "\\hfill{}\n";
3205 if (par_sep == BufferParams::PARSEP_INDENT) {
3206 os << "{\\setlength\\parindent{0pt}\n";
3209 os << "\\begin{minipage}";
3210 switch (params.pextraAlignment()) {
3211 case MINIPAGE_ALIGN_TOP:
3214 case MINIPAGE_ALIGN_MIDDLE:
3217 case MINIPAGE_ALIGN_BOTTOM:
3221 if (!params.pextraWidth().empty()) {
3222 os << '{' << params.pextraWidth() << "}\n";
3224 //float ib = atof(par->pextra_width.c_str())/100;
3225 // string can't handle floats at present
3226 // so I'll do a conversion by hand knowing that
3227 // the limits are 0.0 to 1.0. ARRae.
3229 switch (params.pextraWidthp().length()) {
3235 << params.pextraWidthp();
3239 << params.pextraWidthp();
3241 os << "\\columnwidth}\n";
3244 if (par_sep == BufferParams::PARSEP_INDENT) {
3245 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3248 minipage_open = true;
3249 minipage_open_depth = params.depth();
3252 #ifdef WITH_WARNINGS
3253 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3254 //I disabled it because it breaks when lists span on several
3257 if (style.isEnvironment()){
3258 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3259 #ifdef FANCY_FOOTNOTE_CODE
3260 if (foot_count < 0) {
3261 // flag that footnote[mark][text] should be
3262 // used for any footnotes from now on
3264 foot_this_level = true;
3267 os << "\\begin{" << style.latexname() << "}{"
3268 << params.labelWidthString() << "}\n";
3269 } else if (style.labeltype == LABEL_BIBLIO) {
3271 os << "\\begin{" << style.latexname() << "}{"
3272 << bibitemWidest(buf)
3274 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3275 #ifdef FANCY_FOOTNOTE_CODE
3276 if (foot_count < 0) {
3277 // flag that footnote[mark][text] should be
3278 // used for any footnotes from now on
3280 foot_this_level = true;
3283 os << "\\begin{" << style.latexname() << '}'
3284 << style.latexparam() << '\n';
3286 os << "\\begin{" << style.latexname() << '}'
3287 << style.latexparam() << '\n';
3290 LyXParagraph * par = this;
3292 par = par->TeXOnePar(buf, bparams,
3296 foot, foot_texrow, foot_count
3300 if (minipage_open && par && !style.isEnvironment() &&
3301 (par->params.pextraType() == PEXTRA_MINIPAGE) &&
3302 par->params.pextraStartMinipage()) {
3303 os << "\\end{minipage}\n";
3305 if (par_sep == BufferParams::PARSEP_INDENT) {
3309 minipage_open = false;
3312 if (par && par->params.depth() > params.depth()) {
3313 if (textclasslist.Style(bparams.textclass,
3314 par->layout).isParagraph()
3316 // How to handle this? (Lgb)
3317 //&& !suffixIs(os, "\n\n")
3319 // There should be at least one '\n' already
3320 // but we need there to be two for Standard
3321 // paragraphs that are depth-increment'ed to be
3322 // output correctly. However, tables can
3323 // also be paragraphs so don't adjust them.
3326 // Will it ever harm to have one '\n' too
3327 // many? i.e. that we sometimes will have
3328 // three in a row. (Lgb)
3332 par = par->TeXDeeper(buf, bparams, os, texrow
3334 ,foot, foot_texrow, foot_count
3339 if (par && par->layout == layout && par->params.depth() == params.depth() &&
3340 (par->params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
3341 if (par->params.pextraHfill() && par->previous() &&
3342 (par->previous()->params.pextraType() == PEXTRA_MINIPAGE)){
3343 os << "\\hfill{}\n";
3346 if (par_sep == BufferParams::PARSEP_INDENT) {
3347 os << "{\\setlength\\parindent{0pt}\n";
3350 os << "\\begin{minipage}";
3351 switch (par->params.pextraAlignment()) {
3352 case MINIPAGE_ALIGN_TOP:
3355 case MINIPAGE_ALIGN_MIDDLE:
3358 case MINIPAGE_ALIGN_BOTTOM:
3362 if (!par->params.pextraWidth().empty()) {
3363 os << '{' << par->params.pextraWidth() << "}\n";
3365 //float ib = atof(par->pextra_widthp.c_str())/100;
3366 // string can't handle floats at present
3367 // so I'll do a conversion by hand knowing that
3368 // the limits are 0.0 to 1.0. ARRae.
3370 switch (par->params.pextraWidthp().length()) {
3375 os << "0." << par->params.pextraWidthp();
3378 os << "0.0" << par->params.pextraWidthp();
3380 os << "\\columnwidth}\n";
3383 if (par_sep == BufferParams::PARSEP_INDENT) {
3384 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3387 minipage_open = true;
3388 minipage_open_depth = par->params.depth();
3392 && par->layout == layout
3393 && par->params.depth() == params.depth()
3395 && par->params.pextraType() == params.pextraType()
3398 && par->footnoteflag == footnoteflag
3402 if (style.isEnvironment()) {
3403 os << "\\end{" << style.latexname() << "}\n";
3406 // maybe this should go after the minipage closes?
3407 if (foot_this_level) {
3408 if (foot_count >= 1) {
3409 if (foot_count > 1) {
3410 os << "\\addtocounter{footnote}{-"
3415 texrow += foot_texrow;
3417 foot_texrow.reset();
3424 if (minipage_open && (minipage_open_depth == params.depth()) &&
3425 (!par || par->params.pextraStartMinipage() ||
3426 par->params.pextraType() != PEXTRA_MINIPAGE)) {
3427 os << "\\end{minipage}\n";
3429 if (par_sep == BufferParams::PARSEP_INDENT) {
3433 if (par && par->params.pextraType() != PEXTRA_MINIPAGE) {
3434 os << "\\medskip\n\n";
3438 minipage_open = false;
3441 os << "\\end{LyXParagraphIndent}\n";
3444 if (!(par && (par->params.pextraType() == PEXTRA_MINIPAGE)
3445 && par->params.pextraHfill())) {
3450 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3451 return par; // ale970302
3456 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3457 BufferParams const & bparams,
3458 ostream & os, TexRow & texrow,
3459 ostream & foot, TexRow & foot_texrow,
3463 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3464 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3465 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3466 "No footnote!" << endl;
3468 LyXParagraph * par = this;
3469 LyXLayout const & style =
3470 textclasslist.Style(bparams.textclass,
3471 previous_->GetLayout());
3473 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3474 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3475 "Float other than footnote in command"
3476 " with moving argument is illegal" << endl;
3479 if (footnotekind != LyXParagraph::FOOTNOTE
3480 && footnotekind != LyXParagraph::MARGIN
3483 // How to solve this?
3484 //&& !suffixIs(file, '\n')
3486 // we need to ensure that real floats like tables and figures
3487 // have their \begin{} on a new line otherwise we can get
3488 // incorrect results when using the endfloat.sty package
3489 // especially if two floats follow one another. ARRae 981022
3490 // NOTE: if the file is length 0 it must have just been
3491 // written out so we assume it ended with a '\n'
3493 // As far as I can see there is never any harm in writing
3494 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3499 bool moving_arg = false;
3500 bool need_closing = false;
3501 bool is_rtl = isRightToLeftPar(bparams);
3503 if (is_rtl != parent_is_rtl) {
3508 need_closing = true;
3511 bool footer_in_body = true;
3512 switch (footnotekind) {
3513 case LyXParagraph::FOOTNOTE:
3514 if (style.intitle) {
3515 os << "\\thanks{\n";
3516 footer_in_body = false;
3519 if (foot_count == -1) {
3520 // we're at depth 0 so we can use:
3521 os << "\\footnote{%\n";
3522 footer_in_body = false;
3524 os << "\\footnotemark{}%\n";
3526 // we only need this when there are
3527 // multiple footnotes
3528 os << "\\stepcounter{footnote}";
3530 os << "\\footnotetext{%\n";
3531 foot_texrow.start(this, 0);
3532 foot_texrow.newline();
3537 case LyXParagraph::MARGIN:
3538 os << "\\marginpar{\n";
3540 case LyXParagraph::FIG:
3541 if (params.pextraType() == PEXTRA_FLOATFLT
3542 && (!params.pextraWidth().empty()
3543 || !params.pextraWidthp().empty())) {
3544 if (!params.pextraWidth().empty())
3545 os << "\\begin{floatingfigure}{"
3546 << params.pextraWidth() << "}\n";
3548 os << "\\begin{floatingfigure}{"
3549 << lyx::atoi(params.pextraWidthp()) / 100.0
3550 << "\\textwidth}\n";
3552 os << "\\begin{figure}";
3553 if (!bparams.float_placement.empty()) {
3554 os << '[' << bparams.float_placement << "]\n";
3560 case LyXParagraph::TAB:
3561 os << "\\begin{table}";
3562 if (!bparams.float_placement.empty()) {
3563 os << '[' << bparams.float_placement << "]\n";
3568 case LyXParagraph::WIDE_FIG:
3569 os << "\\begin{figure*}";
3570 if (!bparams.float_placement.empty()) {
3571 os << '[' << bparams.float_placement << "]\n";
3576 case LyXParagraph::WIDE_TAB:
3577 os << "\\begin{table*}";
3578 if (!bparams.float_placement.empty()) {
3579 os << '[' << bparams.float_placement << "]\n";
3584 case LyXParagraph::ALGORITHM:
3585 os << "\\begin{algorithm}\n";
3590 if (footnotekind != LyXParagraph::FOOTNOTE
3591 || !footer_in_body) {
3592 // Process text for all floats except footnotes in body
3594 LyXLayout const & style =
3596 .Style(bparams.textclass, par->layout);
3598 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3600 if (style.isEnvironment()
3601 || par->params.pextraType() == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3602 // Allows the use of minipages within float
3603 // environments. Shouldn't be circular because
3604 // we don't support footnotes inside
3605 // floats (yet). ARRae
3606 par = par->TeXEnvironment(buf, bparams, os,
3611 par = par->TeXOnePar(buf, bparams,
3612 os, texrow, moving_arg,
3617 if (par && !par->IsDummy() && par->params.depth() > params.depth()) {
3618 par = par->TeXDeeper(buf, bparams, os, texrow,
3622 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3624 // process footnotes > depth 0 or in environments separately
3625 // NOTE: Currently don't support footnotes within footnotes
3626 // even though that is possible using the \footnotemark
3627 std::ostringstream dummy;
3628 TexRow dummy_texrow;
3629 int dummy_count = 0;
3631 LyXLayout const & style =
3633 .Style(bparams.textclass, par->layout);
3635 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3637 if (style.isEnvironment()
3638 || par->params.pextraType() == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3639 // Allows the use of minipages within float
3640 // environments. Shouldn't be circular because
3641 // we don't support footnotes inside
3642 // floats (yet). ARRae
3643 par = par->TeXEnvironment(buf, bparams,
3645 dummy, dummy_texrow,
3648 par = par->TeXOnePar(buf, bparams,
3651 dummy, dummy_texrow,
3655 if (par && !par->IsDummy() && par->params.depth() > params.depth()) {
3656 par = par->TeXDeeper(buf, bparams,
3658 dummy, dummy_texrow,
3662 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3664 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3665 "Footnote in a Footnote -- not supported"
3670 switch (footnotekind) {
3671 case LyXParagraph::FOOTNOTE:
3672 if (footer_in_body) {
3673 // This helps tell which of the multiple
3674 // footnotetexts an error was in.
3676 foot_texrow.newline();
3681 case LyXParagraph::MARGIN:
3684 case LyXParagraph::FIG:
3685 if (params.pextraType() == PEXTRA_FLOATFLT
3686 && (!params.pextraWidth().empty()
3687 || !params.pextraWidthp().empty()))
3688 os << "\\end{floatingfigure}";
3690 os << "\\end{figure}";
3692 case LyXParagraph::TAB:
3693 os << "\\end{table}";
3695 case LyXParagraph::WIDE_FIG:
3696 os << "\\end{figure*}";
3698 case LyXParagraph::WIDE_TAB:
3699 os << "\\end{table*}";
3701 case LyXParagraph::ALGORITHM:
3702 os << "\\end{algorithm}";
3709 if (footnotekind != LyXParagraph::FOOTNOTE
3710 && footnotekind != LyXParagraph::MARGIN) {
3711 // we need to ensure that real floats like tables and figures
3712 // have their \end{} on a line of their own otherwise we can
3713 // get incorrect results when using the endfloat.sty package.
3718 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next_ << endl;
3723 bool LyXParagraph::IsDummy() const
3725 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous_
3726 && previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3731 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
3732 int type, string const & width,
3733 string const & widthp)
3735 params.pextraType(type);
3736 params.pextraWidth(width);
3737 params.pextraWidthp(widthp);
3739 if (textclasslist.Style(bparams.textclass,
3740 layout).isEnvironment()) {
3741 LyXParagraph * par = this;
3742 LyXParagraph * ppar = par;
3744 while (par && (par->layout == layout)
3745 && (par->params.depth() == params.depth())) {
3747 par = par->previous();
3750 par = par->FirstPhysicalPar();
3752 while (par && par->params.depth() > params.depth()) {
3753 par = par->previous();
3756 par = par->FirstPhysicalPar();
3761 while (par && (par->layout == layout)
3762 && (par->params.depth() == params.depth())) {
3763 par->params.pextraType(type);
3764 par->params.pextraWidth(width);
3765 par->params.pextraWidthp(widthp);
3767 par = par->NextAfterFootnote();
3771 if (par && (par->params.depth() > params.depth()))
3772 par->SetPExtraType(bparams,
3773 type, width, widthp);
3775 while (par && ((par->params.depth() > params.depth()) || par->IsDummy()))
3776 par = par->NextAfterFootnote();
3778 while (par && par->params.depth() > params.depth())
3786 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
3788 if (params.pextraType() == PEXTRA_NONE)
3791 params.pextraType(PEXTRA_NONE);
3792 params.pextraWidth(string());
3793 params.pextraWidthp(string());
3795 if (textclasslist.Style(bparams.textclass,
3796 layout).isEnvironment()) {
3797 LyXParagraph * par = this;
3798 LyXParagraph * ppar = par;
3800 while (par && (par->layout == layout)
3801 && (par->params.depth() == params.depth())) {
3803 par = par->previous();
3806 par = par->FirstPhysicalPar();
3808 while (par && par->params.depth() > params.depth()) {
3809 par = par->previous();
3812 par = par->FirstPhysicalPar();
3817 while (par && (par->layout == layout)
3818 && (par->params.depth() == params.depth())) {
3819 par->params.pextraType(PEXTRA_NONE);
3820 par->params.pextraWidth(string());
3821 par->params.pextraWidthp(string());
3823 par = par->NextAfterFootnote();
3827 if (par && (par->params.depth() > params.depth()))
3828 par->UnsetPExtraType(bparams);
3830 while (par && ((par->params.depth() > params.depth()) || par->IsDummy()))
3831 par = par->NextAfterFootnote();
3833 while (par && par->params.depth() > params.depth())
3842 bool LyXParagraph::IsHfill(size_type pos) const
3844 return IsHfillChar(GetChar(pos));
3848 bool LyXParagraph::IsInset(size_type pos) const
3850 return IsInsetChar(GetChar(pos));
3855 bool LyXParagraph::IsFloat(size_type pos) const
3857 return IsFloatChar(GetChar(pos));
3862 bool LyXParagraph::IsNewline(size_type pos) const
3864 return pos >= 0 && IsNewlineChar(GetChar(pos));
3868 bool LyXParagraph::IsSeparator(size_type pos) const
3870 return IsSeparatorChar(GetChar(pos));
3874 bool LyXParagraph::IsLineSeparator(size_type pos) const
3876 return IsLineSeparatorChar(GetChar(pos));
3880 bool LyXParagraph::IsKomma(size_type pos) const
3882 return IsKommaChar(GetChar(pos));
3886 /// Used by the spellchecker
3887 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
3889 value_type const c = GetChar(pos);
3890 if (IsLetterChar(c))
3892 // '\0' is not a letter, allthough every string contains "" (below)
3895 // We want to pass the ' and escape chars to ispell
3896 string const extra = lyxrc.isp_esc_chars + '\'';
3897 char ch[2] = { c, 0 };
3898 return contains(extra, ch);
3902 bool LyXParagraph::IsWord(size_type pos ) const
3904 return IsWordChar(GetChar(pos)) ;
3909 LyXParagraph::getParLanguage(BufferParams const & bparams) const
3913 return FirstPhysicalPar()->getParLanguage(bparams);
3917 return GetFirstFontSettings().language();
3919 return previous_->getParLanguage(bparams);
3921 return bparams.language;
3925 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
3927 return lyxrc.rtl_support
3928 && getParLanguage(bparams)->RightToLeft();
3932 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
3933 Language const * from, Language const * to)
3935 for (size_type i = 0; i < size(); ++i) {
3936 LyXFont font = GetFontSettings(bparams, i);
3937 if (font.language() == from) {
3938 font.setLanguage(to);
3945 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
3947 Language const * doc_language = bparams.language;
3948 for (FontList::const_iterator cit = fontlist.begin();
3949 cit != fontlist.end(); ++cit)
3950 if ((*cit).font().language() != doc_language)
3956 // Convert the paragraph to a string.
3957 // Used for building the table of contents
3958 string const LyXParagraph::String(Buffer const * buffer, bool label)
3960 BufferParams const & bparams = buffer->params;
3963 if (label && !IsDummy() && !params.labelString().empty())
3965 if (label && !params.labelString().empty())
3967 s += params.labelString() + ' ';
3968 string::size_type const len = s.size();
3970 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
3971 value_type c = GetChar(i);
3974 else if (c == META_INSET &&
3975 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
3976 std::ostringstream ost;
3977 GetInset(i)->Ascii(buffer, ost);
3978 s += subst(ost.str().c_str(),'\n',' ');
3983 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
3984 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
3985 s += NextAfterFootnote()->String(buffer, false);
3989 if (isRightToLeftPar(bparams))
3990 reverse(s.begin() + len,s.end());
3998 string const LyXParagraph::String(Buffer const * buffer,
3999 LyXParagraph::size_type beg,
4000 LyXParagraph::size_type end)
4005 if (beg == 0 && !IsDummy() && !params.labelString().empty())
4007 if (beg == 0 && !params.labelString().empty())
4009 s += params.labelString() + ' ';
4011 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4012 value_type c = GetUChar(buffer->params, i);
4015 else if (c == META_INSET) {
4016 std::ostringstream ost;
4017 GetInset(i)->Ascii(buffer, ost);
4018 s += ost.str().c_str();
4026 void LyXParagraph::SetInsetOwner(Inset * i)
4029 for (InsetList::const_iterator cit = insetlist.begin();
4030 cit != insetlist.end(); ++cit) {
4032 (*cit).inset->setOwner(i);
4037 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4040 for (InsetList::const_iterator cit = insetlist.begin();
4041 cit != insetlist.end(); ++cit) {
4043 if ((*cit).inset->IsTextInset()) {
4044 static_cast<UpdatableInset *>
4045 ((*cit).inset)->deleteLyXText(bv);
4052 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4055 for (InsetList::const_iterator cit = insetlist.begin();
4056 cit != insetlist.end(); ++cit) {
4058 if ((*cit).inset->IsTextInset()) {
4059 static_cast<UpdatableInset *>
4060 ((*cit).inset)->resizeLyXText(bv);
4067 void LyXParagraph::fitToSize()
4069 TextContainer tmp(text.begin(), text.end());
4074 void LyXParagraph::setContentsFromPar(LyXParagraph * par)