1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
25 #include "tex-strings.h"
27 #include "bufferparams.h"
28 #include "support/FileInfo.h"
29 #include "support/LAssert.h"
31 #include "LaTeXFeatures.h"
32 #include "insets/insetinclude.h"
33 #include "insets/insetbib.h"
34 #include "insets/insettext.h"
35 #include "support/filetools.h"
36 #include "lyx_gui_misc.h"
38 #include "support/lyxmanip.h"
39 #include "BufferView.h"
41 #include "ParameterStruct.h"
47 using std::lower_bound;
48 using std::upper_bound;
51 int tex_code_break_column = 72; // needs non-zero initialization. set later.
52 // this is a bad idea, but how can LyXParagraph find its buffer to get
53 // parameters? (JMarc)
55 extern string bibitemWidest(Buffer const *);
57 // this is a minibuffer
58 static char minibuffer_char;
59 static LyXFont minibuffer_font;
60 static Inset * minibuffer_inset;
63 extern BufferView * current_view;
65 // Initialization of the counter for the paragraph id's,
66 // declared in lyxparagraph.h
67 unsigned int LyXParagraph::paragraph_id = 0;
69 // Initialize static member.
70 ShareContainer<LyXFont> LyXParagraph::FontTable::container;
73 LyXParagraph::LyXParagraph()
75 text.reserve(500); // is this number too big?
76 for (int i = 0; i < 10; ++i) setCounter(i , 0);
82 footnoteflag = LyXParagraph::NO_FOOTNOTE;
83 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
88 bibkey = 0; // ale970302
93 // This konstruktor inserts the new paragraph in a list.
94 LyXParagraph::LyXParagraph(LyXParagraph * par)
99 for (int i = 0; i < 10; ++i) setCounter(i, 0);
102 // double linked list begin
105 next_->previous_ = this;
107 previous_->next_ = this;
110 footnoteflag = LyXParagraph::NO_FOOTNOTE;
111 footnotekind = LyXParagraph::FOOTNOTE;
114 id_ = paragraph_id++;
116 bibkey = 0; // ale970302
122 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
123 BufferParams const & bparams,
124 char footflag, char dth) const
127 if (footnoteflag != LyXParagraph::NO_FOOTNOTE ||
129 || previous_->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
130 // The beginning or the end of a footnote environment?
131 if (footflag != footnoteflag) {
132 footflag = footnoteflag;
134 os << "\n\\begin_float "
135 << string_footnotekinds[footnotekind]
138 os << "\n\\end_float ";
142 // The beginning or end of a deeper (i.e. nested) area?
143 if (dth != params.depth()) {
144 if (params.depth() > dth) {
145 while (params.depth() > dth) {
146 os << "\n\\begin_deeper ";
150 while (params.depth() < dth) {
151 os << "\n\\end_deeper ";
157 // First write the layout
159 << textclasslist.NameOfLayout(bparams.textclass, layout)
162 // Maybe some vertical spaces.
163 if (params.spaceTop().kind() != VSpace::NONE)
164 os << "\\added_space_top "
165 << params.spaceTop().asLyXCommand() << " ";
166 if (params.spaceBottom().kind() != VSpace::NONE)
167 os << "\\added_space_bottom "
168 << params.spaceBottom().asLyXCommand() << " ";
170 // Maybe the paragraph has special spacing
171 params.spacing().writeFile(os, true);
173 // The labelwidth string used in lists.
174 if (!params.labelWidthString().empty())
175 os << "\\labelwidthstring "
176 << params.labelWidthString() << '\n';
178 // Lines above or below?
179 if (params.lineTop())
181 if (params.lineBottom())
182 os << "\\line_bottom ";
184 // Pagebreaks above or below?
185 if (params.pagebreakTop())
186 os << "\\pagebreak_top ";
187 if (params.pagebreakBottom())
188 os << "\\pagebreak_bottom ";
190 // Start of appendix?
191 if (params.startOfAppendix())
192 os << "\\start_of_appendix ";
195 if (params.noindent())
199 if (params.align() != LYX_ALIGN_LAYOUT) {
201 switch (params.align()) {
202 case LYX_ALIGN_LEFT: h = 1; break;
203 case LYX_ALIGN_RIGHT: h = 2; break;
204 case LYX_ALIGN_CENTER: h = 3; break;
205 default: h = 0; break;
207 os << "\\align " << string_align[h] << " ";
209 if (params.pextraType() != PEXTRA_NONE) {
210 os << "\\pextra_type " << params.pextraType();
211 if (params.pextraType() == PEXTRA_MINIPAGE) {
212 os << " \\pextra_alignment "
213 << params.pextraAlignment();
214 if (params.pextraHfill())
215 os << " \\pextra_hfill "
216 << params.pextraHfill();
217 if (params.pextraStartMinipage())
218 os << " \\pextra_start_minipage "
219 << params.pextraStartMinipage();
221 if (!params.pextraWidth().empty()) {
222 os << " \\pextra_width "
223 << VSpace(params.pextraWidth()).asLyXCommand();
224 } else if (!params.pextraWidthp().empty()) {
225 os << " \\pextra_widthp "
226 << params.pextraWidthp();
232 // Dummy layout. This means that a footnote ended.
233 os << "\n\\end_float ";
234 footflag = LyXParagraph::NO_FOOTNOTE;
240 bibkey->Write(buf, os);
242 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
245 for (size_type i = 0; i < size(); ++i) {
251 // Write font changes
252 LyXFont font2 = GetFontSettings(bparams, i);
253 if (font2 != font1) {
254 font2.lyxWriteChanges(font1, os);
259 value_type const c = GetChar(i);
263 Inset const * inset = GetInset(i);
265 if (inset->DirectWrite()) {
266 // international char, let it write
267 // code directly so it's shorter in
269 inset->Write(buf, os);
271 os << "\n\\begin_inset ";
272 inset->Write(buf, os);
273 os << "\n\\end_inset \n\n";
279 os << "\n\\newline \n";
283 os << "\n\\hfill \n";
287 os << "\n\\backslash \n";
291 if (i + 1 < size() && GetChar(i + 1) == ' ') {
298 if ((column > 70 && c == ' ')
303 // this check is to amend a bug. LyX sometimes
304 // inserts '\0' this could cause problems.
308 lyxerr << "ERROR (LyXParagraph::writeFile):"
309 " NULL char in structure." << endl;
315 // now write the next paragraph
317 next_->writeFile(buf, os, bparams, footflag, dth);
321 void LyXParagraph::validate(LaTeXFeatures & features) const
323 BufferParams const & bparams = features.bufferParams();
326 // this will be useful later
327 LyXLayout const & layout =
328 textclasslist.Style(bparams.textclass,
333 if (params.lineTop() || params.lineBottom())
334 features.lyxline = true;
335 if (!params.spacing().isDefault())
336 features.setspace = true;
339 features.layout[GetLayout()] = true;
342 Language const * doc_language = bparams.language;
344 for (FontList::const_iterator cit = fontlist.begin();
345 cit != fontlist.end(); ++cit) {
346 if ((*cit).font().noun() == LyXFont::ON) {
347 lyxerr[Debug::LATEX] << "font.noun: "
348 << (*cit).font().noun()
350 features.noun = true;
351 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
352 << (*cit).font().stateText(0)
355 switch ((*cit).font().color()) {
357 case LColor::inherit:
361 features.color = true;
362 lyxerr[Debug::LATEX] << "Color enabled. Font: "
363 << (*cit).font().stateText(0)
367 Language const * language = (*cit).font().language();
368 if (language->babel() != doc_language->babel()) {
369 features.UsedLanguages.insert(language);
370 lyxerr[Debug::LATEX] << "Found language "
371 << language->babel() << endl;
376 for (InsetList::const_iterator cit = insetlist.begin();
377 cit != insetlist.end(); ++cit) {
379 (*cit).inset->Validate(features);
382 if (params.pextraType() == PEXTRA_INDENT)
383 features.LyXParagraphIndent = true;
384 if (params.pextraType() == PEXTRA_FLOATFLT)
385 features.floatflt = true;
387 if (layout.needprotect
388 && next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
389 features.NeedLyXFootnoteCode = true;
391 if (bparams.paragraph_separation == BufferParams::PARSEP_INDENT
392 && params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE)
393 features.NeedLyXMinipageIndent = true;
395 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
396 features.algorithm = true;
401 // First few functions needed for cut and paste and paragraph breaking.
402 void LyXParagraph::CopyIntoMinibuffer(Buffer const & buffer,
403 LyXParagraph::size_type pos) const
405 BufferParams bparams = buffer.params;
407 minibuffer_char = GetChar(pos);
408 minibuffer_font = GetFontSettings(bparams, pos);
409 minibuffer_inset = 0;
410 if (minibuffer_char == LyXParagraph::META_INSET) {
412 minibuffer_inset = GetInset(pos)->Clone(buffer);
414 minibuffer_inset = 0;
415 minibuffer_char = ' ';
416 // This reflects what GetInset() does (ARRae)
422 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
423 LyXParagraph::size_type pos)
425 minibuffer_char = GetChar(pos);
426 minibuffer_font = GetFontSettings(bparams, pos);
427 minibuffer_inset = 0;
428 if (minibuffer_char == LyXParagraph::META_INSET) {
430 minibuffer_inset = GetInset(pos);
431 // This is a little hack since I want exactly
432 // the inset, not just a clone. Otherwise
433 // the inset would be deleted when calling Erase(pos)
435 InsetTable search_elem(pos, 0);
436 InsetList::iterator it =
437 lower_bound(insetlist.begin(),
439 search_elem, matchIT());
440 if (it != insetlist.end() && (*it).pos == pos)
443 minibuffer_inset = 0;
444 minibuffer_char = ' ';
445 // This reflects what GetInset() does (ARRae)
450 // Erase(pos); now the caller is responsible for that.
454 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
456 if ((minibuffer_char == LyXParagraph::META_INSET) &&
457 !InsertInsetAllowed(minibuffer_inset))
459 if (minibuffer_char == LyXParagraph::META_INSET)
460 InsertInset(pos, minibuffer_inset, minibuffer_font);
462 InsertChar(pos, minibuffer_char, minibuffer_font);
470 void LyXParagraph::Clear()
479 // the destructor removes the new paragraph from the list
480 LyXParagraph::~LyXParagraph()
483 previous_->next_ = next_;
485 next_->previous_ = previous_;
487 for (InsetList::iterator it = insetlist.begin();
488 it != insetlist.end(); ++it) {
495 //lyxerr << "LyXParagraph::paragraph_id = "
496 // << LyXParagraph::paragraph_id << endl;
500 void LyXParagraph::Erase(LyXParagraph::size_type pos)
503 // > because last is the next unused position, and you can
504 // use it if you want
506 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
507 NextAfterFootnote()->Erase(pos - text.size() - 1);
509 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
510 "position does not exist." << endl;
514 Assert(pos < size());
517 if (pos < size()) { // last is free for insertation, but should be empty
519 // if it is an inset, delete the inset entry
520 if (text[pos] == LyXParagraph::META_INSET) {
522 InsetTable search_inset(pos, 0);
523 InsetList::iterator it =
524 lower_bound(insetlist.begin(),
526 search_inset, matchIT());
527 if (it != insetlist.end() && (*it).pos == pos) {
533 text.erase(text.begin() + pos);
535 // Erase entries in the tables.
536 FontTable search_font(pos, LyXFont());
538 FontList::iterator it =
539 lower_bound(fontlist.begin(),
541 search_font, matchFT());
542 if (it != fontlist.end() && (*it).pos() == pos &&
544 (it != fontlist.begin() && (*(it - 1)).pos() == pos - 1))) {
545 // If it is a multi-character font
546 // entry, we just make it smaller
547 // (see update below), otherwise we
549 unsigned int const i = it - fontlist.begin();
550 fontlist.erase(fontlist.begin() + i);
551 it = fontlist.begin() + i;
552 if (i > 0 && i < fontlist.size() &&
553 fontlist[i - 1].font() == fontlist[i].font()) {
554 fontlist.erase(fontlist.begin() + i - 1);
555 it = fontlist.begin() + i - 1;
559 // Update all other entries.
560 FontList::iterator fend = fontlist.end();
561 for (; it != fend; ++it)
562 (*it).pos((*it).pos() - 1);
564 // Update the inset table.
565 InsetTable search_inset(pos, 0);
566 InsetList::iterator lend = insetlist.end();
567 for (InsetList::iterator it =
568 upper_bound(insetlist.begin(),
570 search_inset, matchIT());
575 lyxerr << "ERROR (LyXParagraph::Erase): "
576 "can't erase non-existant char." << endl;
582 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
583 LyXParagraph::value_type c)
585 LyXFont const f(LyXFont::ALL_INHERIT);
586 InsertChar(pos, c, f);
590 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
591 LyXParagraph::value_type c,
592 LyXFont const & font)
595 // > because last is the next unused position, and you can
596 // use it if you want
599 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
600 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
603 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
604 "position does not exist." << endl;
608 Assert(pos <= size());
610 text.insert(text.begin() + pos, c);
612 // Update the font table.
613 FontTable search_font(pos, LyXFont());
614 for (FontList::iterator it = lower_bound(fontlist.begin(),
616 search_font, matchFT());
617 it != fontlist.end(); ++it)
618 (*it).pos((*it).pos() + 1);
620 // Update the inset table.
621 InsetTable search_inset(pos, 0);
622 for (InsetList::iterator it = lower_bound(insetlist.begin(),
624 search_inset, matchIT());
625 it != insetlist.end(); ++it)
632 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
635 LyXFont const f(LyXFont::ALL_INHERIT);
636 InsertInset(pos, inset, f);
640 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
641 Inset * inset, LyXFont const & font)
646 // > because last is the next unused position, and you can
647 // use it if you want
650 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
652 ->InsertInset(pos - text.size() - 1,
655 lyxerr << "ERROR (LyXParagraph::InsertInset): "
656 "position does not exist: " << pos << endl;
660 Assert(pos <= size());
663 InsertChar(pos, META_INSET, font);
664 Assert(text[pos] == META_INSET);
666 // Add a new entry in the inset table.
667 InsetTable search_inset(pos, 0);
668 InsetList::iterator it = lower_bound(insetlist.begin(),
670 search_inset, matchIT());
671 if (it != insetlist.end() && (*it).pos == pos)
672 lyxerr << "ERROR (LyXParagraph::InsertInset): "
673 "there is an inset in position: " << pos << endl;
675 insetlist.insert(it, InsetTable(pos, inset));
677 inset->setOwner(inset_owner);
681 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
683 //lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
686 return inset_owner->InsertInsetAllowed(inset);
691 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
696 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
697 return NextAfterFootnote()
698 ->GetInset(pos - text.size() - 1);
700 lyxerr << "ERROR (LyXParagraph::GetInset): "
701 "position does not exist: "
707 Assert(pos < size());
710 InsetTable search_inset(pos, 0);
711 InsetList::iterator it = lower_bound(insetlist.begin(),
713 search_inset, matchIT());
714 if (it != insetlist.end() && (*it).pos == pos)
717 lyxerr << "ERROR (LyXParagraph::GetInset): "
718 "Inset does not exist: " << pos << endl;
721 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
722 // Did this commenting out introduce a bug? So far I have not
723 // see any, please enlighten me. (Lgb)
724 // My guess is that since the inset does not exist, we might
725 // as well replace it with a space to prevent craches. (Asger)
730 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
735 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
736 return NextAfterFootnote()
737 ->GetInset(pos - text.size() - 1);
739 lyxerr << "ERROR (LyXParagraph::GetInset): "
740 "position does not exist: "
746 Assert(pos < size());
749 InsetTable search_inset(pos, 0);
750 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
752 search_inset, matchIT());
753 if (cit != insetlist.end() && (*cit).pos == pos)
756 lyxerr << "ERROR (LyXParagraph::GetInset): "
757 "Inset does not exist: " << pos << endl;
759 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
760 // Did this commenting out introduce a bug? So far I have not
761 // see any, please enlighten me. (Lgb)
762 // My guess is that since the inset does not exist, we might
763 // as well replace it with a space to prevent craches. (Asger)
768 // Gets uninstantiated font setting at position.
769 // Optimized after profiling. (Asger)
770 LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
771 LyXParagraph::size_type pos) const
774 Assert(pos <= size());
779 FontTable search_font(pos, LyXFont());
780 FontList::const_iterator cit = lower_bound(fontlist.begin(),
782 search_font, matchFT());
783 if (cit != fontlist.end())
784 return (*cit).font();
789 // > because last is the next unused position, and you can
790 // use it if you want
791 else if (pos > size()) {
793 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
794 return NextAfterFootnote()
795 ->GetFontSettings(bparams,
796 pos - text.size() - 1);
798 // Why is it an error to ask for the font of a
799 // position that does not exist? Would it be
800 // enough for this to be enabled on debug?
801 // We want strict error checking, but it's ok to only
802 // have it when debugging. (Asger)
803 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
804 "position does not exist. "
805 << pos << " (" << static_cast<int>(pos)
807 } else if (pos > 0) {
808 return GetFontSettings(bparams, pos - 1);
811 if (pos == size() && size())
812 return GetFontSettings(bparams, pos - 1);
816 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
818 //return LyXFont(LyXFont::ALL_INHERIT);
822 // Gets uninstantiated font setting at position 0
823 LyXFont const LyXParagraph::GetFirstFontSettings() const
826 if (!fontlist.empty())
827 return fontlist[0].font();
831 else if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
832 return NextAfterFootnote()->GetFirstFontSettings();
834 return LyXFont(LyXFont::ALL_INHERIT);
838 // Gets the fully instantiated font at a given position in a paragraph
839 // This is basically the same function as LyXText::GetFont() in text2.C.
840 // The difference is that this one is used for generating the LaTeX file,
841 // and thus cosmetic "improvements" are disallowed: This has to deliver
842 // the true picture of the buffer. (Asger)
843 // If position is -1, we get the layout font of the paragraph.
844 // If position is -2, we get the font of the manual label of the paragraph.
845 LyXFont const LyXParagraph::getFont(BufferParams const & bparams,
846 LyXParagraph::size_type pos) const
849 LyXLayout const & layout =
850 textclasslist.Style(bparams.textclass,
852 LyXParagraph::size_type main_body = 0;
853 if (layout.labeltype == LABEL_MANUAL)
854 main_body = BeginningOfMainBody();
859 layoutfont = layout.labelfont;
861 layoutfont = layout.font;
862 tmpfont = GetFontSettings(bparams, pos);
863 tmpfont.realize(layoutfont);
865 // process layoutfont for pos == -1 and labelfont for pos < -1
867 tmpfont = layout.font;
869 tmpfont = layout.labelfont;
870 tmpfont.setLanguage(getParLanguage(bparams));
873 // check for environment font information
874 char par_depth = GetDepth();
875 LyXParagraph const * par = this;
876 while (par && par_depth && !tmpfont.resolved()) {
877 par = par->DepthHook(par_depth - 1);
879 tmpfont.realize(textclasslist.
880 Style(bparams.textclass,
881 par->GetLayout()).font);
882 par_depth = par->GetDepth();
886 tmpfont.realize(textclasslist
887 .TextClass(bparams.textclass)
893 /// Returns the height of the highest font in range
895 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
896 LyXParagraph::size_type endpos) const
898 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
899 if (fontlist.empty())
902 FontTable end_search(endpos, LyXFont());
903 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
905 end_search, matchFT());
906 if (end_it != fontlist.end())
909 FontTable start_search(startpos, LyXFont());
910 for (FontList::const_iterator cit =
911 lower_bound(fontlist.begin(),
913 start_search, matchFT());
914 cit != end_it; ++cit) {
915 LyXFont::FONT_SIZE size = (*cit).font().size();
916 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
923 LyXParagraph::value_type
924 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
929 Assert(pos <= size());
930 if (!size() || pos == size()) return '\0';
941 // > because last is the next unused position, and you can
942 // use it if you want
943 else if (pos > size()) {
944 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
945 return NextAfterFootnote()
946 ->GetChar(pos - text.size() - 1);
949 lyxerr << "ERROR (LyXParagraph::GetChar const): "
950 "position does not exist."
951 << pos << " (" << static_cast<int>(pos)
957 // We should have a footnote environment.
958 if (!next_ || next_->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
959 // Notice that LyX does request the
960 // last char from time to time. (Asger)
961 //lyxerr << "ERROR (LyXParagraph::GetChar): "
962 // "expected footnote." << endl;
965 switch (next_->footnotekind) {
966 case LyXParagraph::FOOTNOTE:
967 return LyXParagraph::META_FOOTNOTE;
968 case LyXParagraph::MARGIN:
969 return LyXParagraph::META_MARGIN;
970 case LyXParagraph::FIG:
971 case LyXParagraph::WIDE_FIG:
972 return LyXParagraph::META_FIG;
973 case LyXParagraph::TAB:
974 case LyXParagraph::WIDE_TAB:
975 return LyXParagraph::META_TAB;
976 case LyXParagraph::ALGORITHM:
977 return LyXParagraph::META_ALGORITHM;
979 return '\0'; // to shut up gcc
985 LyXParagraph::value_type
986 LyXParagraph::GetUChar(BufferParams const & bparams,
987 LyXParagraph::size_type pos) const
989 value_type c = GetChar(pos);
990 if (!lyxrc.rtl_support)
1020 if (uc != c && GetFontSettings(bparams, pos).isRightToLeft())
1026 // return an string of the current word, and the end of the word in lastpos.
1027 string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1029 Assert(lastpos >= 0);
1031 // the current word is defined as starting at the first character
1032 // from the immediate left of lastpospos which meets the definition
1033 // of IsLetter(), continuing to the last character to the right
1034 // of this meeting IsLetter.
1040 // move back until we have a letter
1042 //there's no real reason to have firstpos & lastpos as
1043 //separate variables as this is written, but maybe someon
1044 // will want to return firstpos in the future.
1046 //since someone might have typed a punctuation first
1047 int firstpos = lastpos;
1049 while ((firstpos >= 0) && !IsLetter(firstpos))
1052 // now find the beginning by looking for a nonletter
1054 while ((firstpos>= 0) && IsLetter(firstpos))
1057 // the above is now pointing to the preceeding non-letter
1061 // so copy characters into theword until we get a nonletter
1062 // note that this can easily exceed lastpos, wich means
1063 // that if used in the middle of a word, the whole word
1066 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1074 LyXParagraph::size_type LyXParagraph::Last() const
1076 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1077 return text.size() + NextAfterFootnote()->Last() + 1;
1078 // the 1 is the symbol
1087 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1089 // > because last is the next unused position, and you can
1090 // use it if you want
1093 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1094 return NextAfterFootnote()
1095 ->ParFromPos(pos - text.size() - 1);
1097 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1098 "position does not exist." << endl;
1107 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1109 // > because last is the next unused position, and you can
1110 // use it if you want
1113 && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1114 return NextAfterFootnote()
1115 ->PositionInParFromPos(pos - text.size() - 1);
1118 "ERROR (LyXParagraph::PositionInParFromPos): "
1119 "position does not exist." << endl;
1128 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1129 LyXFont const & font)
1132 // > because last is the next unused position, and you can
1133 // use it if you want
1136 next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1137 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1140 lyxerr << "ERROR (LyXParagraph::SetFont): "
1141 "position does not exist." << endl;
1146 Assert(pos <= size());
1149 // First, reduce font against layout/label font
1150 // Update: The SetCharFont() routine in text2.C already
1151 // reduces font, so we don't need to do that here. (Asger)
1152 // No need to simplify this because it will disappear
1153 // in a new kernel. (Asger)
1154 // Next search font table
1156 FontTable search_font(pos, LyXFont());
1157 FontList::iterator it = lower_bound(fontlist.begin(),
1159 search_font, matchFT());
1160 unsigned int i = it - fontlist.begin();
1161 bool notfound = it == fontlist.end();
1163 if (!notfound && fontlist[i].font() == font)
1166 bool begin = pos == 0 || notfound ||
1167 (i > 0 && fontlist[i-1].pos() == pos - 1);
1168 // Is position pos is a beginning of a font block?
1169 bool end = !notfound && fontlist[i].pos() == pos;
1170 // Is position pos is the end of a font block?
1171 if (begin && end) { // A single char block
1172 if (i + 1 < fontlist.size() &&
1173 fontlist[i + 1].font() == font) {
1174 // Merge the singleton block with the next block
1175 fontlist.erase(fontlist.begin() + i);
1176 if (i > 0 && fontlist[i - 1].font() == font)
1177 fontlist.erase(fontlist.begin() + i-1);
1178 } else if (i > 0 && fontlist[i - 1].font() == font) {
1179 // Merge the singleton block with the previous block
1180 fontlist[i - 1].pos(pos);
1181 fontlist.erase(fontlist.begin() + i);
1183 fontlist[i].font(font);
1185 if (i > 0 && fontlist[i - 1].font() == font)
1186 fontlist[i - 1].pos(pos);
1188 fontlist.insert(fontlist.begin() + i,
1189 FontTable(pos, font));
1191 fontlist[i].pos(pos - 1);
1192 if (!(i + 1 < fontlist.size() &&
1193 fontlist[i + 1].font() == font))
1194 fontlist.insert(fontlist.begin() + i + 1,
1195 FontTable(pos, font));
1196 } else { // The general case. The block is splitted into 3 blocks
1197 fontlist.insert(fontlist.begin() + i,
1198 FontTable(pos - 1, fontlist[i].font()));
1199 fontlist.insert(fontlist.begin() + i + 1,
1200 FontTable(pos, font));
1206 void LyXParagraph::next(LyXParagraph * p)
1212 // This function is able to hide closed footnotes.
1213 LyXParagraph * LyXParagraph::next()
1216 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1217 LyXParagraph * tmp = next_;
1219 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1221 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1222 return tmp->next(); /* there can be more than one
1223 footnote in a logical
1226 return next_; // This should never happen!
1233 LyXParagraph const * LyXParagraph::next() const
1236 if (next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1237 LyXParagraph * tmp = next_;
1239 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1241 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1242 return tmp->next(); /* there can be more than one
1243 footnote in a logical
1246 return next_; // This should never happen!
1254 LyXParagraph * LyXParagraph::NextAfterFootnote()
1256 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1257 LyXParagraph * tmp = next_;
1258 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1260 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1261 return tmp; /* there can be more than one footnote
1262 in a logical paragraph */
1264 return next_; // This should never happen!
1272 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1274 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1275 LyXParagraph * tmp = next_;
1276 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1278 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1279 return tmp; /* there can be more than one footnote
1280 in a logical paragraph */
1282 return next_; // This should never happen!
1290 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1293 if (previous_ && previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1295 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1296 tmp = tmp->previous_;
1297 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1298 return tmp; /* there can be more than one footnote
1299 in a logical paragraph */
1301 return previous_; // This should never happen!
1309 LyXParagraph * LyXParagraph::LastPhysicalPar()
1311 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1314 LyXParagraph * tmp = this;
1316 && tmp->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1317 tmp = tmp->NextAfterFootnote();
1325 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1327 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1330 LyXParagraph const * tmp = this;
1332 && tmp->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1333 tmp = tmp->NextAfterFootnote();
1341 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1345 LyXParagraph * tmppar = this;
1349 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1350 tmppar = tmppar->previous_;
1361 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1365 LyXParagraph const * tmppar = this;
1369 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1370 tmppar = tmppar->previous_;
1380 void LyXParagraph::previous(LyXParagraph * p)
1386 // This function is able to hide closed footnotes.
1387 LyXParagraph * LyXParagraph::previous()
1390 LyXParagraph * tmp = previous_;
1395 && tmp->previous_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1396 tmp = tmp->previous_;
1398 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1399 tmp = tmp->previous_;
1400 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1401 return tmp->next_->previous();
1411 // This function is able to hide closed footnotes.
1412 LyXParagraph const * LyXParagraph::previous() const
1415 LyXParagraph * tmp = previous_;
1419 && tmp->previous_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1420 tmp = tmp->previous_;
1422 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1423 tmp = tmp->previous_;
1424 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1425 return tmp->next_->previous();
1435 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1436 LyXParagraph::size_type pos,
1441 // create a new paragraph
1444 size_type pos_first;
1445 LyXParagraph * par = ParFromPos(pos);
1446 LyXParagraph * firstpar = FirstPhysicalPar();
1448 LyXParagraph * tmp = new LyXParagraph(par);
1450 //LyXParagraph * par = this;
1451 //LyXParagraph * firstpar = this;
1452 LyXParagraph * tmp = new LyXParagraph(this);
1456 tmp->footnoteflag = footnoteflag;
1457 tmp->footnotekind = footnotekind;
1459 // this is an idea for a more userfriendly layout handling, I will
1460 // see what the users say
1463 // layout stays the same with latex-environments
1465 tmp->SetOnlyLayout(bparams, firstpar->layout);
1466 tmp->SetLabelWidthString(firstpar->params.labelWidthString());
1469 // layout stays the same with latex-environments
1471 tmp->SetOnlyLayout(bparams, layout);
1472 tmp->SetLabelWidthString(params.labelWidthString());
1476 if (Last() > pos || !Last() || flag == 2) {
1477 tmp->SetOnlyLayout(bparams, firstpar->layout);
1478 tmp->params.align(firstpar->params.align());
1479 tmp->SetLabelWidthString(firstpar->params.labelWidthString());
1481 tmp->params.lineBottom(firstpar->params.lineBottom());
1482 firstpar->params.lineBottom(false);
1483 tmp->params.pagebreakBottom(firstpar->params.pagebreakBottom());
1484 firstpar->params.pagebreakBottom(false);
1485 tmp->params.spaceBottom(firstpar->params.spaceBottom());
1486 firstpar->params.spaceBottom(VSpace(VSpace::NONE));
1488 tmp->params.depth(firstpar->params.depth());
1489 tmp->params.noindent(firstpar->params.noindent());
1491 if (size() > pos || !size() || flag == 2) {
1492 tmp->SetOnlyLayout(bparams, layout);
1493 tmp->params.align(params.align());
1494 tmp->SetLabelWidthString(params.labelWidthString());
1496 tmp->params.lineBottom(params.lineBottom());
1497 params.lineBottom(false);
1498 tmp->params.pagebreakBottom(params.pagebreakBottom());
1499 params.pagebreakBottom(false);
1500 tmp->params.spaceBottom(params.spaceBottom());
1501 params.spaceBottom(VSpace(VSpace::NONE));
1503 tmp->params.depth(params.depth());
1504 tmp->params.noindent(params.noindent());
1506 // copy everything behind the break-position
1507 // to the new paragraph
1510 while (ParFromPos(pos_first) != par)
1512 pos_end = pos_first + par->text.size() - 1;
1515 for (i = j = pos; i <= pos_end; ++i) {
1516 par->CutIntoMinibuffer(bparams, i - pos_first);
1517 if (tmp->InsertFromMinibuffer(j - pos))
1523 for (i = pos_end; i >= pos; --i)
1524 par->Erase(i - pos_first);
1528 size_type pos_end = text.size() - 1;
1530 for (i = j = pos; i <= pos_end; ++i) {
1531 CutIntoMinibuffer(bparams, i);
1532 if (tmp->InsertFromMinibuffer(j - pos))
1536 for (i = pos_end; i >= pos; --i)
1544 // just an idea of me
1546 tmp->params.lineTop(firstpar->params.lineTop());
1547 tmp->params.pagebreakTop(firstpar->params.pagebreakTop());
1548 tmp->params.spaceTop(firstpar->params.spaceTop());
1549 tmp->bibkey = firstpar->bibkey;
1551 // layout stays the same with latex-environments
1553 firstpar->SetOnlyLayout(bparams, tmp->layout);
1554 firstpar->SetLabelWidthString(tmp->params.labelWidthString());
1555 firstpar->params.depth(tmp->params.depth());
1559 // just an idea of me
1561 tmp->params.lineTop(params.lineTop());
1562 tmp->params.pagebreakTop(params.pagebreakTop());
1563 tmp->params.spaceTop(params.spaceTop());
1564 tmp->bibkey = bibkey;
1566 // layout stays the same with latex-environments
1568 SetOnlyLayout(bparams, tmp->layout);
1569 SetLabelWidthString(tmp->params.labelWidthString());
1570 params.depth(tmp->params.depth());
1577 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1580 par = par->FirstPhysicalPar();
1581 footnoteflag = par->footnoteflag;
1582 footnotekind = par->footnotekind;
1584 layout = par->layout;
1585 params.makeSame(par->params);
1587 // This can be changed after NEW_INSETS is in effect. (Lgb)
1588 SetLabelWidthString(par->params.labelWidthString());
1593 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1595 LyXParagraph * tmppar = this;
1598 && tmppar->previous_->footnoteflag ==
1599 LyXParagraph::CLOSED_FOOTNOTE)
1600 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1601 tmppar = tmppar->previous_;
1604 return this; // This should never happen!
1611 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1613 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1623 && (IsNewline(0) || IsLineSeparator(0))){
1634 LyXParagraph * LyXParagraph::Clone() const
1636 // create a new paragraph
1637 LyXParagraph * result = new LyXParagraph;
1639 result->MakeSameLayout(this);
1641 // this is because of the dummy layout of the paragraphs that
1643 result->layout = layout;
1645 result->inset_owner = inset_owner;
1649 result->bibkey = static_cast<InsetBibKey *>
1650 (bibkey->Clone(*current_view->buffer()));
1654 // copy everything behind the break-position to the new paragraph
1656 result->text = text;
1657 result->fontlist = fontlist;
1658 result->insetlist = insetlist;
1659 for (InsetList::iterator it = result->insetlist.begin();
1660 it != result->insetlist.end(); ++it)
1661 (*it).inset = (*it).inset->Clone(*current_view->buffer());
1666 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1669 par = par->FirstPhysicalPar();
1674 par->footnoteflag == footnoteflag &&
1675 par->footnotekind == footnotekind &&
1677 par->layout == layout &&
1678 params.sameLayout(par->params);
1682 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1683 LyXParagraph::size_type pos)
1686 // create a new paragraph
1687 LyXParagraph * par = ParFromPos(pos);
1689 LyXParagraph * tmp = new LyXParagraph(par);
1691 tmp->MakeSameLayout(par);
1693 // When can pos < Last()?
1694 // I guess pos == Last() is possible.
1696 // copy everything behind the break-position to the new
1698 size_type pos_first = 0;
1699 while (ParFromPos(pos_first) != par)
1701 size_type pos_end = pos_first + par->text.size() - 1;
1704 for (i = j = pos; i <= pos_end; ++i) {
1705 par->CutIntoMinibuffer(bparams, i - pos_first);
1706 if (tmp->InsertFromMinibuffer(j - pos))
1712 for (size_type i = pos_end; i >= pos; --i)
1713 par->Erase(i - pos_first);
1718 // create a new paragraph
1719 LyXParagraph * tmp = new LyXParagraph(this);
1720 tmp->MakeSameLayout(this);
1722 // When can pos > Last()?
1723 // I guess pos == Last() is possible.
1725 // copy everything behind the break-position to the new
1727 size_type pos_end = text.size() - 1;
1730 for (i = j = pos; i <= pos_end; ++i) {
1731 CutIntoMinibuffer(bparams, i);
1732 if (tmp->InsertFromMinibuffer(j - pos))
1738 for (size_type i = pos_end; i >= pos; --i)
1747 // Be carefull, this does not make any check at all.
1748 // This method has wrong name, it combined this par with the next par.
1749 // In that sense it is the reverse of break paragraph. (Lgb)
1750 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1752 // copy the next paragraph to this one
1753 LyXParagraph * the_next = next();
1755 // first the DTP-stuff
1757 LyXParagraph * firstpar = FirstPhysicalPar();
1758 firstpar->params.lineBottom(the_next->params.lineBottom());
1759 firstpar->params.spaceBottom(the_next->params.spaceBottom());
1760 firstpar->params.pagebreakBottom(the_next->params.pagebreakBottom());
1762 size_type pos_end = the_next->text.size() - 1;
1763 size_type pos_insert = Last();
1765 params.lineBottom(the_next->params.lineBottom());
1766 params.spaceBottom(the_next->params.spaceBottom());
1767 params.pagebreakBottom(the_next->params.pagebreakBottom());
1769 size_type pos_end = the_next->text.size() - 1;
1770 size_type pos_insert = size();
1773 // ok, now copy the paragraph
1775 for (i = j = 0; i <= pos_end; ++i) {
1776 the_next->CutIntoMinibuffer(bparams, i);
1777 if (InsertFromMinibuffer(pos_insert + j))
1781 // delete the next paragraph
1782 LyXParagraph * ppar = the_next->previous_;
1783 LyXParagraph * npar = the_next->next_;
1790 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1792 LyXParagraph * par = ParFromPos(pos);
1794 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1795 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1801 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1803 LyXParagraph * par = ParFromPos(pos);
1805 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1806 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1813 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1815 LyXParagraph const * par = this;
1816 int par_depth = GetDepth();
1818 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1819 int const endlabeltype =
1820 textclasslist.Style(bparams.textclass,
1821 layout).endlabeltype;
1822 if (endlabeltype != END_LABEL_NO_LABEL) {
1823 LyXParagraph const * last = this;
1825 if (footnoteflag == NO_FOOTNOTE)
1826 last = LastPhysicalPar();
1827 else if (next_->footnoteflag == NO_FOOTNOTE)
1828 return endlabeltype;
1833 if (!last || !last->next_)
1834 return endlabeltype;
1836 int next_depth = last->next_->GetDepth();
1837 if (par_depth > next_depth ||
1838 (par_depth == next_depth && layout != last->next_->GetLayout() ))
1839 return endlabeltype;
1844 par = par->DepthHook(par_depth - 1);
1846 par_depth = par->GetDepth();
1848 return END_LABEL_NO_LABEL;
1852 LyXTextClass::size_type LyXParagraph::GetLayout() const
1855 return FirstPhysicalPar()->layout;
1862 char LyXParagraph::GetDepth() const
1865 return FirstPhysicalPar()->params.depth();
1867 return params.depth();
1872 char LyXParagraph::GetAlign() const
1875 return FirstPhysicalPar()->params.align();
1877 return params.align();
1882 string const & LyXParagraph::GetLabelstring() const
1885 return FirstPhysicalPar()->params.labelString();
1887 return params.labelString();
1892 int LyXParagraph::GetFirstCounter(int i) const
1895 return FirstPhysicalPar()->counter_[i];
1902 // the next two functions are for the manual labels
1903 string const LyXParagraph::GetLabelWidthString() const
1906 if (!FirstPhysicalPar()->params.labelWidthString().empty())
1907 return FirstPhysicalPar()->params.labelWidthString();
1909 if (!params.labelWidthString().empty())
1910 return params.labelWidthString();
1913 return _("Senseless with this layout!");
1917 void LyXParagraph::SetLabelWidthString(string const & s)
1920 LyXParagraph * par = FirstPhysicalPar();
1922 par->params.labelWidthString(s);
1924 params.labelWidthString(s);
1929 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1930 LyXTextClass::size_type new_layout)
1933 LyXParagraph * par = FirstPhysicalPar();
1935 LyXParagraph * par = this;
1937 LyXParagraph * ppar = 0;
1938 LyXParagraph * npar = 0;
1940 par->layout = new_layout;
1942 if (par->params.pextraType() == PEXTRA_NONE) {
1943 if (par->previous()) {
1945 ppar = par->previous()->FirstPhysicalPar();
1947 ppar = par->previous();
1951 && (ppar->params.depth() > par->params.depth()))
1953 ppar = ppar->previous()->FirstPhysicalPar();
1955 ppar = ppar->previous();
1960 npar = par->next()->NextAfterFootnote();
1966 && (npar->params.depth() > par->params.depth()))
1968 npar = npar->next()->NextAfterFootnote();
1970 npar = npar->next();
1973 if (ppar && (ppar->params.pextraType() != PEXTRA_NONE)) {
1974 string p1 = ppar->params.pextraWidth();
1975 string p2 = ppar->params.pextraWidthp();
1976 ppar->SetPExtraType(bparams,
1977 ppar->params.pextraType(),
1980 if ((par->params.pextraType() == PEXTRA_NONE) &&
1981 npar && (npar->params.pextraType() != PEXTRA_NONE)) {
1982 string const p1 = npar->params.pextraWidth();
1983 string const p2 = npar->params.pextraWidthp();
1984 npar->SetPExtraType(bparams, npar->params.pextraType(),
1991 void LyXParagraph::SetLayout(BufferParams const & bparams,
1992 LyXTextClass::size_type new_layout)
1996 * par = FirstPhysicalPar(),
2003 par->layout = new_layout;
2004 par->params.labelWidthString(string());
2005 par->params.align(LYX_ALIGN_LAYOUT);
2006 par->params.spaceTop(VSpace(VSpace::NONE));
2007 par->params.spaceBottom(VSpace(VSpace::NONE));
2008 par->params.spacing(Spacing(Spacing::Default));
2010 if (par->params.pextraType() == PEXTRA_NONE) {
2011 if (par->previous()) {
2013 ppar = par->previous()->FirstPhysicalPar();
2015 ppar = par->previous();
2019 && (ppar->params.depth() > par->params.depth()))
2021 ppar = ppar->previous()->FirstPhysicalPar();
2023 ppar = ppar->previous();
2028 npar = par->next()->NextAfterFootnote();
2034 && (npar->params.depth() > par->params.depth()))
2036 npar = npar->next()->NextAfterFootnote();
2038 npar = npar->next();
2041 if (ppar && (ppar->params.pextraType() != PEXTRA_NONE)) {
2042 string const p1 = ppar->params.pextraWidth();
2043 string const p2 = ppar->params.pextraWidthp();
2044 ppar->SetPExtraType(bparams, ppar->params.pextraType(),
2047 if ((par->params.pextraType() == PEXTRA_NONE) &&
2048 npar && (npar->params.pextraType() != PEXTRA_NONE)) {
2049 string const p1 = npar->params.pextraWidth();
2050 string const p2 = npar->params.pextraWidthp();
2051 npar->SetPExtraType(bparams, npar->params.pextraType(),
2058 // if the layout of a paragraph contains a manual label, the beginning of the
2059 // main body is the beginning of the second word. This is what the par-
2060 // function returns. If the layout does not contain a label, the main
2061 // body always starts with position 0. This differentiation is necessary,
2062 // because there cannot be a newline or a blank <= the beginning of the
2063 // main body in TeX.
2065 int LyXParagraph::BeginningOfMainBody() const
2068 if (FirstPhysicalPar() != this)
2071 // Unroll the first two cycles of the loop
2072 // and remember the previous character to
2073 // remove unnecessary GetChar() calls
2076 && GetChar(i) != LyXParagraph::META_NEWLINE
2079 char previous_char = 0;
2082 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2083 // Yes, this ^ is supposed to be "= " not "=="
2086 && previous_char != ' '
2087 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2089 previous_char = temp;
2095 if (i == 0 && i == size() &&
2096 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2097 && next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2098 ++i; /* the cursor should not jump
2099 * to the main body if there
2106 LyXParagraph * LyXParagraph::DepthHook(int deth)
2108 LyXParagraph * newpar = this;
2114 newpar = newpar->FirstPhysicalPar()->previous();
2116 newpar = newpar->previous();
2118 } while (newpar && newpar->GetDepth() > deth
2120 && newpar->footnoteflag == footnoteflag
2125 if (previous() || GetDepth())
2126 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2131 return newpar->FirstPhysicalPar();
2138 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2140 LyXParagraph const * newpar = this;
2146 newpar = newpar->FirstPhysicalPar()->previous();
2148 newpar = newpar->previous();
2150 } while (newpar && newpar->GetDepth() > deth
2152 && newpar->footnoteflag == footnoteflag
2157 if (previous() || GetDepth())
2158 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2163 return newpar->FirstPhysicalPar();
2170 int LyXParagraph::AutoDeleteInsets()
2173 InsetList::size_type index = 0;
2174 while (index < insetlist.size()) {
2175 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2176 Erase(insetlist[index].pos);
2177 // Erase() calls to insetlist.erase(&insetlist[index])
2178 // so index shouldn't be increased.
2187 LyXParagraph::inset_iterator
2188 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2190 InsetTable search_inset(pos, 0);
2191 InsetList::iterator it = lower_bound(insetlist.begin(),
2193 search_inset, matchIT());
2194 return inset_iterator(it);
2198 // returns -1 if inset not found
2199 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2202 for (InsetList::const_iterator cit = insetlist.begin();
2203 cit != insetlist.end(); ++cit) {
2204 if ((*cit).inset == inset) {
2208 if (inset == bibkey)
2212 // Think about footnotes.
2213 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2214 && next_ && next_->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2216 NextAfterFootnote()->GetPositionOfInset(inset);
2218 return text.size() + 1 + further;
2225 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2226 BufferParams const & bparams,
2227 ostream & os, TexRow & texrow,
2232 TexRow & foot_texrow,
2237 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2238 LyXLayout const & style =
2239 textclasslist.Style(bparams.textclass,
2242 bool further_blank_line = false;
2245 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2248 if (params.startOfAppendix()) {
2249 os << "\\appendix\n";
2253 if (!params.spacing().isDefault()
2254 && (!previous() || !previous()->HasSameLayout(this))) {
2255 os << params.spacing().writeEnvirBegin() << "\n";
2259 if (tex_code_break_column && style.isCommand()){
2264 if (params.pagebreakTop()) {
2266 further_blank_line = true;
2268 if (params.spaceTop().kind() != VSpace::NONE) {
2269 os << params.spaceTop().asLatexCommand(bparams);
2270 further_blank_line = true;
2273 if (params.lineTop()) {
2274 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2275 << "\\vspace{-1\\parskip}";
2276 further_blank_line = true;
2279 if (further_blank_line){
2284 Language const * language = getParLanguage(bparams);
2285 Language const * doc_language = bparams.language;
2286 Language const * previous_language = previous_
2287 ? previous_->getParLanguage(bparams) : doc_language;
2288 if (language->babel() != doc_language->babel() &&
2289 language->babel() != previous_language->babel()) {
2290 os << subst(lyxrc.language_command_begin, "$$lang",
2296 if (bparams.inputenc == "auto" &&
2297 language->encoding() != previous_language->encoding()) {
2298 os << "\\inputencoding{"
2299 << language->encoding()->LatexName()
2304 switch (style.latextype) {
2307 << style.latexname()
2308 << style.latexparam();
2310 case LATEX_ITEM_ENVIRONMENT:
2312 bibkey->Latex(buf, os, false, false);
2316 case LATEX_LIST_ENVIRONMENT:
2323 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2325 LyXParagraph * par = next_;
2327 // Spit out footnotes
2328 if (lyxrc.rtl_support) {
2329 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
2330 && next_->footnoteflag != footnoteflag) {
2331 LyXParagraph * p = 0;
2332 bool is_rtl = (size() > 0)
2333 ? GetFontSettings(bparams,
2334 size()-1).isRightToLeft()
2335 : language->RightToLeft();
2336 if ((p = NextAfterFootnote()) != 0 &&
2338 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2339 is_rtl = getParLanguage(bparams)->RightToLeft();
2340 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2341 && par->footnoteflag != footnoteflag) {
2342 par = par->TeXFootnote(buf, bparams,
2344 foot_texrow, foot_count,
2346 par->SimpleTeXOnePar(buf, bparams,
2347 os, texrow, moving_arg);
2348 is_rtl = (par->size() > 0)
2349 ? par->GetFontSettings(bparams,
2350 par->size()-1).isRightToLeft()
2351 : language->RightToLeft();
2353 par->next_->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2354 (p = par->NextAfterFootnote()) != 0 &&
2356 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2357 is_rtl = language->RightToLeft();
2362 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2363 && par->footnoteflag != footnoteflag) {
2364 par = par->TeXFootnote(buf, bparams,
2366 foot, foot_texrow, foot_count,
2368 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2374 // Make sure that \\par is done with the font of the last
2375 // character if this has another size as the default.
2376 // This is necessary because LaTeX (and LyX on the screen)
2377 // calculates the space between the baselines according
2378 // to this font. (Matthias)
2380 // Is this really needed ? (Dekel)
2381 // We do not need to use to change the font for the last paragraph
2382 // or for a command.
2384 LyXFont font = getFont(bparams, Last() - 1);
2386 LyXFont font = getFont(bparams, size() - 1);
2388 bool is_command = textclasslist.Style(bparams.textclass,
2389 GetLayout()).isCommand();
2390 if (style.resfont.size() != font.size() && next_ && !is_command) {
2393 os << "\\" << font.latexSize() << " \\par}";
2394 } else if (need_par) {
2396 } else if (is_command)
2399 if (language->babel() != doc_language->babel() &&
2402 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2404 || par->getParLanguage(bparams)->babel() != language->babel())) {
2406 << subst(lyxrc.language_command_end, "$$lang",
2407 doc_language->babel());
2410 switch (style.latextype) {
2411 case LATEX_ITEM_ENVIRONMENT:
2412 case LATEX_LIST_ENVIRONMENT:
2413 if (par && (params.depth() < par->params.depth())) {
2418 case LATEX_ENVIRONMENT:
2419 // if its the last paragraph of the current environment
2420 // skip it otherwise fall through
2422 && (par->layout != layout
2423 || par->params.depth() != params.depth()
2424 || par->params.pextraType() != params.pextraType()))
2427 // we don't need it for the last paragraph!!!
2428 // or for tables in floats
2429 // -- effectively creates a \par where there isn't one which
2430 // breaks a \subfigure or \subtable.
2432 // && footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2438 further_blank_line = false;
2439 if (params.lineBottom()) {
2441 os << "\\lyxline{\\" << getFont(bparams,
2442 Last() - 1).latexSize() << '}';
2444 os << "\\lyxline{\\" << getFont(bparams,
2445 size() - 1).latexSize() << '}';
2447 further_blank_line = true;
2450 if (params.spaceBottom().kind() != VSpace::NONE) {
2451 os << params.spaceBottom().asLatexCommand(bparams);
2452 further_blank_line = true;
2455 if (params.pagebreakBottom()) {
2457 further_blank_line = true;
2460 if (further_blank_line){
2465 if (!params.spacing().isDefault()
2466 && (!par || !par->HasSameLayout(this))) {
2467 os << params.spacing().writeEnvirEnd() << "\n";
2471 // we don't need it for the last paragraph!!!
2474 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2475 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2482 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2487 // This one spits out the text of the paragraph
2488 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2489 BufferParams const & bparams,
2490 ostream & os, TexRow & texrow,
2493 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2495 bool return_value = false;
2497 LyXLayout const & style =
2498 textclasslist.Style(bparams.textclass,
2500 LyXFont basefont, last_font;
2502 // Maybe we have to create a optional argument.
2503 size_type main_body;
2504 if (style.labeltype != LABEL_MANUAL)
2507 main_body = BeginningOfMainBody();
2509 if (main_body > 0) {
2511 basefont = getFont(bparams, -2); // Get label font
2513 basefont = getFont(bparams, -1); // Get layout font
2524 if (style.isCommand()) {
2527 } else if (params.align() != LYX_ALIGN_LAYOUT) {
2530 return_value = true;
2534 moving_arg |= style.needprotect;
2536 // Which font is currently active?
2537 LyXFont running_font(basefont);
2538 // Do we have an open font change?
2539 bool open_font = false;
2541 texrow.start(this, 0);
2543 for (size_type i = 0; i < size(); ++i) {
2545 // First char in paragraph or after label?
2551 if (main_body > 0) {
2553 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2556 basefont = getFont(bparams, -1); // Now use the layout font
2557 running_font = basefont;
2561 if (style.isCommand()) {
2564 } else if (params.align() != LYX_ALIGN_LAYOUT && next_) {
2565 // We do not need \par here (Dekel)
2569 return_value = true;
2572 if (params.noindent()) {
2573 os << "\\noindent ";
2576 switch (params.align()) {
2577 case LYX_ALIGN_NONE:
2578 case LYX_ALIGN_BLOCK:
2579 case LYX_ALIGN_LAYOUT:
2580 case LYX_ALIGN_SPECIAL:
2582 case LYX_ALIGN_LEFT:
2585 if (getParLanguage(bparams)->babel() != "hebrew") {
2586 os << "\\raggedright ";
2589 os << "\\raggedleft ";
2593 case LYX_ALIGN_RIGHT:
2596 if (getParLanguage(bparams)->babel() != "hebrew") {
2597 os << "\\raggedleft ";
2600 os << "\\raggedright ";
2604 case LYX_ALIGN_CENTER:
2607 os << "\\centering ";
2613 value_type c = GetChar(i);
2615 // Fully instantiated font
2616 LyXFont font = getFont(bparams, i);
2618 LyXParagraph * p = 0;
2621 previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2622 (p = PreviousBeforeFootnote()) != 0)
2623 last_font = p->getFont(bparams, p->size() - 1);
2626 last_font = running_font;
2628 // Spaces at end of font change are simulated to be
2629 // outside font change, i.e. we write "\textXX{text} "
2630 // rather than "\textXX{text }". (Asger)
2631 if (open_font && c == ' ' && i <= size() - 2
2632 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2633 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2634 font = getFont(bparams, i + 1);
2636 // We end font definition before blanks
2637 if (!font.equalExceptLatex(running_font) && open_font) {
2638 column += running_font.latexWriteEndChanges(os,
2640 (i == main_body-1) ? basefont : font);
2641 running_font = basefont;
2645 // Blanks are printed before start of fontswitch
2647 // Do not print the separation of the optional argument
2648 if (i != main_body - 1) {
2649 SimpleTeXBlanks(os, texrow, i,
2650 column, font, style);
2654 // Do we need to change font?
2655 if (!font.equalExceptLatex(running_font)
2656 && i != main_body-1) {
2657 column += font.latexWriteStartChanges(os, basefont,
2659 running_font = font;
2663 if (c == LyXParagraph::META_NEWLINE) {
2664 // newlines are handled differently here than
2665 // the default in SimpleTeXSpecialChars().
2666 if (!style.newline_allowed
2667 || font.latex() == LyXFont::ON) {
2671 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2674 basefont = getFont(bparams, -1);
2675 running_font = basefont;
2676 if (font.family() ==
2677 LyXFont::TYPEWRITER_FAMILY) {
2685 texrow.start(this, i + 1);
2688 SimpleTeXSpecialChars(buf, bparams,
2689 os, texrow, moving_arg,
2690 font, running_font, basefont,
2691 open_font, style, i, column, c);
2695 // If we have an open font definition, we have to close it
2697 LyXParagraph * p = 0;
2700 && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
2701 && (p = NextAfterFootnote()) != 0
2706 running_font.latexWriteEndChanges(os, basefont,
2707 p->getFont(bparams, 0));
2709 running_font.latexWriteEndChanges(os, basefont, basefont);
2712 // Needed if there is an optional argument but no contents.
2713 if (main_body > 0 && main_body == size()) {
2715 return_value = false;
2718 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2719 return return_value;
2723 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2725 bool retval = false;
2727 case LyXParagraph::META_HFILL:
2728 sgml_string.erase();
2730 case LyXParagraph::META_NEWLINE:
2734 sgml_string = "&";
2737 sgml_string = "<";
2740 sgml_string = ">";
2743 sgml_string = "$";
2746 sgml_string = "#";
2749 sgml_string = "%";
2752 sgml_string = "[";
2755 sgml_string = "]";
2758 sgml_string = "{";
2761 sgml_string = "}";
2764 sgml_string = "˜";
2767 sgml_string = """;
2770 sgml_string = "\";
2776 case '\0': // Ignore :-)
2777 sgml_string.erase();
2787 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
2788 LyXParagraph::size_type const i,
2789 int & column, LyXFont const & font,
2790 LyXLayout const & style)
2792 if (column > tex_code_break_column
2794 && GetChar(i - 1) != ' '
2796 // In LaTeX mode, we don't want to
2797 // break lines since some commands
2799 && ! (font.latex() == LyXFont::ON)
2800 // same in FreeSpacing mode
2801 && !style.free_spacing
2802 // In typewriter mode, we want to avoid
2803 // ! . ? : at the end of a line
2804 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
2805 && (GetChar(i-1) == '.'
2806 || GetChar(i-1) == '?'
2807 || GetChar(i-1) == ':'
2808 || GetChar(i-1) == '!'))) {
2809 if (tex_code_break_column == 0) {
2810 // in batchmode we need LaTeX to still
2811 // see it as a space not as an extra '\n'
2817 texrow.start(this, i + 1);
2819 } else if (font.latex() == LyXFont::OFF) {
2820 if (style.free_spacing) {
2829 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
2830 BufferParams const & bparams,
2831 ostream & os, TexRow & texrow,
2834 LyXFont & running_font,
2837 LyXLayout const & style,
2838 LyXParagraph::size_type & i,
2840 LyXParagraph::value_type const c)
2842 // Two major modes: LaTeX or plain
2843 // Handle here those cases common to both modes
2844 // and then split to handle the two modes separately.
2846 case LyXParagraph::META_INSET: {
2847 Inset * inset = GetInset(i);
2850 int const len = os.tellp();
2851 //ostream::pos_type const len = os.tellp();
2852 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
2853 || inset->LyxCode() == Inset::MATH_CODE
2854 || inset->LyxCode() == Inset::URL_CODE)
2855 && running_font.isRightToLeft()) {
2860 int tmp = inset->Latex(buf, os, moving_arg,
2861 style.free_spacing);
2869 column += int(os.tellp()) - len;
2878 case LyXParagraph::META_NEWLINE:
2880 column += running_font.latexWriteEndChanges(os,
2885 basefont = getFont(bparams, -1);
2886 running_font = basefont;
2889 case LyXParagraph::META_HFILL:
2895 // And now for the special cases within each mode
2896 // Are we in LaTeX mode?
2897 if (font.latex() == LyXFont::ON) {
2898 // at present we only have one option
2899 // but I'll leave it as a switch statement
2900 // so its simpler to extend. (ARRae)
2903 // make sure that we will not print
2904 // error generating chars to the tex
2905 // file. This test would not be needed
2906 // if it were done in the buffer
2914 // Plain mode (i.e. not LaTeX)
2917 os << "\\textbackslash{}";
2921 case '°': case '±': case '²': case '³':
2922 case '×': case '÷': case '¹': case 'ª':
2923 case 'º': case '¬': case 'µ':
2924 if (bparams.inputenc == "latin1" ||
2925 (bparams.inputenc == "auto" &&
2926 font.language()->encoding()->LatexName()
2928 os << "\\ensuremath{"
2937 case '|': case '<': case '>':
2938 // In T1 encoding, these characters exist
2939 if (lyxrc.fontenc == "T1") {
2941 //... but we should avoid ligatures
2942 if ((c == '>' || c == '<')
2944 && GetChar(i + 1) == c) {
2945 //os << "\\textcompwordmark{}";
2946 // Jean-Marc, have a look at
2947 // this. IÂ think this works
2955 // Typewriter font also has them
2956 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
2960 // Otherwise, we use what LaTeX
2964 os << "\\textless{}";
2968 os << "\\textgreater{}";
2972 os << "\\textbar{}";
2978 case '-': // "--" in Typewriter mode -> "-{}-"
2980 && GetChar(i + 1) == '-'
2981 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
2990 os << "\\char`\\\"{}";
2995 if (bparams.inputenc == "default") {
3004 case '%': case '#': case '{':
3011 os << "\\textasciitilde{}";
3016 os << "\\textasciicircum{}";
3020 case '*': case '[': case ']':
3021 // avoid being mistaken for optional arguments
3022 os << '{' << c << '}';
3027 // Blanks are printed before font switching.
3028 // Sure? I am not! (try nice-latex)
3029 // I am sure it's correct. LyX might be smarter
3030 // in the future, but for now, nothing wrong is
3035 /* idea for labels --- begin*/
3039 && font.family() != LyXFont::TYPEWRITER_FAMILY
3040 && GetChar(i + 1) == 'y'
3041 && GetChar(i + 2) == 'X') {
3049 && font.family() != LyXFont::TYPEWRITER_FAMILY
3050 && GetChar(i + 1) == 'e'
3051 && GetChar(i + 2) == 'X') {
3056 // Check for "LaTeX2e"
3059 && font.family() != LyXFont::TYPEWRITER_FAMILY
3060 && GetChar(i + 1) == 'a'
3061 && GetChar(i + 2) == 'T'
3062 && GetChar(i + 3) == 'e'
3063 && GetChar(i + 4) == 'X'
3064 && GetChar(i + 5) == '2'
3065 && GetChar(i + 6) == 'e') {
3070 // Check for "LaTeX"
3073 && font.family() != LyXFont::TYPEWRITER_FAMILY
3074 && GetChar(i + 1) == 'a'
3075 && GetChar(i + 2) == 'T'
3076 && GetChar(i + 3) == 'e'
3077 && GetChar(i + 4) == 'X') {
3081 /* idea for labels --- end*/
3082 } else if (c != '\0') {
3092 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3093 BufferParams const & bparams,
3094 ostream & os, TexRow & texrow
3097 TexRow & foot_texrow,
3102 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3103 LyXParagraph * par = this;
3106 (par->params.depth() == params.depth())
3108 && (par->footnoteflag == footnoteflag)
3113 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3115 if (textclasslist.Style(bparams.textclass,
3116 par->layout).isEnvironment()
3117 || par->params.pextraType() != PEXTRA_NONE) {
3118 par = par->TeXEnvironment(buf, bparams,
3126 par = par->TeXOnePar(buf, bparams,
3136 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3142 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3143 BufferParams const & bparams,
3144 ostream & os, TexRow & texrow
3147 TexRow & foot_texrow,
3152 bool eindent_open = false;
3154 bool foot_this_level = false;
3156 // flags when footnotetext should be appended to file.
3157 static bool minipage_open = false;
3158 static int minipage_open_depth = 0;
3159 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,
3171 if (params.pextraType() == PEXTRA_INDENT) {
3172 if (!params.pextraWidth().empty()) {
3173 os << "\\begin{LyXParagraphIndent}{"
3174 << params.pextraWidth() << "}\n";
3176 //float ib = atof(pextra_widthp.c_str())/100;
3177 // string can't handle floats at present (971109)
3178 // so I'll do a conversion by hand knowing that
3179 // the limits are 0.0 to 1.0. ARRae.
3180 os << "\\begin{LyXParagraphIndent}{";
3181 switch (params.pextraWidthp().length()) {
3187 << params.pextraWidthp();
3191 << params.pextraWidthp();
3193 os << "\\columnwidth}\n";
3196 eindent_open = true;
3198 if ((params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
3199 if (params.pextraHfill() && previous() &&
3200 (previous()->params.pextraType() == PEXTRA_MINIPAGE)) {
3201 os << "\\hfill{}\n";
3204 if (par_sep == BufferParams::PARSEP_INDENT) {
3205 os << "{\\setlength\\parindent{0pt}\n";
3208 os << "\\begin{minipage}";
3209 switch (params.pextraAlignment()) {
3210 case MINIPAGE_ALIGN_TOP:
3213 case MINIPAGE_ALIGN_MIDDLE:
3216 case MINIPAGE_ALIGN_BOTTOM:
3220 if (!params.pextraWidth().empty()) {
3221 os << '{' << params.pextraWidth() << "}\n";
3223 //float ib = atof(par->pextra_width.c_str())/100;
3224 // string can't handle floats at present
3225 // so I'll do a conversion by hand knowing that
3226 // the limits are 0.0 to 1.0. ARRae.
3228 switch (params.pextraWidthp().length()) {
3234 << params.pextraWidthp();
3238 << params.pextraWidthp();
3240 os << "\\columnwidth}\n";
3243 if (par_sep == BufferParams::PARSEP_INDENT) {
3244 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3247 minipage_open = true;
3248 minipage_open_depth = params.depth();
3251 #ifdef WITH_WARNINGS
3252 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3253 //I disabled it because it breaks when lists span on several
3256 if (style.isEnvironment()){
3257 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3258 #ifdef FANCY_FOOTNOTE_CODE
3259 if (foot_count < 0) {
3260 // flag that footnote[mark][text] should be
3261 // used for any footnotes from now on
3263 foot_this_level = true;
3266 os << "\\begin{" << style.latexname() << "}{"
3267 << params.labelWidthString() << "}\n";
3268 } else if (style.labeltype == LABEL_BIBLIO) {
3270 os << "\\begin{" << style.latexname() << "}{"
3271 << bibitemWidest(buf)
3273 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3274 #ifdef FANCY_FOOTNOTE_CODE
3275 if (foot_count < 0) {
3276 // flag that footnote[mark][text] should be
3277 // used for any footnotes from now on
3279 foot_this_level = true;
3282 os << "\\begin{" << style.latexname() << '}'
3283 << style.latexparam() << '\n';
3285 os << "\\begin{" << style.latexname() << '}'
3286 << style.latexparam() << '\n';
3289 LyXParagraph * par = this;
3291 par = par->TeXOnePar(buf, bparams,
3295 foot, foot_texrow, foot_count
3299 if (minipage_open && par && !style.isEnvironment() &&
3300 (par->params.pextraType() == PEXTRA_MINIPAGE) &&
3301 par->params.pextraStartMinipage()) {
3302 os << "\\end{minipage}\n";
3304 if (par_sep == BufferParams::PARSEP_INDENT) {
3308 minipage_open = false;
3310 if (par && par->params.depth() > params.depth()) {
3311 if (textclasslist.Style(bparams.textclass,
3312 par->layout).isParagraph()
3314 // How to handle this? (Lgb)
3315 //&& !suffixIs(os, "\n\n")
3317 // There should be at least one '\n' already
3318 // but we need there to be two for Standard
3319 // paragraphs that are depth-increment'ed to be
3320 // output correctly. However, tables can
3321 // also be paragraphs so don't adjust them.
3324 // Will it ever harm to have one '\n' too
3325 // many? i.e. that we sometimes will have
3326 // three in a row. (Lgb)
3330 par = par->TeXDeeper(buf, bparams, os, texrow
3332 ,foot, foot_texrow, foot_count
3336 if (par && par->layout == layout && par->params.depth() == params.depth() &&
3337 (par->params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
3338 if (par->params.pextraHfill() && par->previous() &&
3339 (par->previous()->params.pextraType() == PEXTRA_MINIPAGE)){
3340 os << "\\hfill{}\n";
3343 if (par_sep == BufferParams::PARSEP_INDENT) {
3344 os << "{\\setlength\\parindent{0pt}\n";
3347 os << "\\begin{minipage}";
3348 switch (par->params.pextraAlignment()) {
3349 case MINIPAGE_ALIGN_TOP:
3352 case MINIPAGE_ALIGN_MIDDLE:
3355 case MINIPAGE_ALIGN_BOTTOM:
3359 if (!par->params.pextraWidth().empty()) {
3360 os << '{' << par->params.pextraWidth() << "}\n";
3362 //float ib = atof(par->pextra_widthp.c_str())/100;
3363 // string can't handle floats at present
3364 // so I'll do a conversion by hand knowing that
3365 // the limits are 0.0 to 1.0. ARRae.
3367 switch (par->params.pextraWidthp().length()) {
3372 os << "0." << par->params.pextraWidthp();
3375 os << "0.0" << par->params.pextraWidthp();
3377 os << "\\columnwidth}\n";
3380 if (par_sep == BufferParams::PARSEP_INDENT) {
3381 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3384 minipage_open = true;
3385 minipage_open_depth = par->params.depth();
3388 && par->layout == layout
3389 && par->params.depth() == params.depth()
3390 && par->params.pextraType() == params.pextraType()
3392 && par->footnoteflag == footnoteflag
3396 if (style.isEnvironment()) {
3397 os << "\\end{" << style.latexname() << '}';
3399 // maybe this should go after the minipage closes?
3400 if (foot_this_level) {
3401 if (foot_count >= 1) {
3402 if (foot_count > 1) {
3403 os << "\\addtocounter{footnote}{-"
3408 texrow += foot_texrow;
3410 foot_texrow.reset();
3416 if (minipage_open && (minipage_open_depth == params.depth()) &&
3417 (!par || par->params.pextraStartMinipage() ||
3418 par->params.pextraType() != PEXTRA_MINIPAGE)) {
3419 os << "\\end{minipage}\n";
3421 if (par_sep == BufferParams::PARSEP_INDENT) {
3425 if (par && par->params.pextraType() != PEXTRA_MINIPAGE) {
3426 os << "\\medskip\n\n";
3430 minipage_open = false;
3433 os << "\\end{LyXParagraphIndent}\n";
3436 if (!(par && (par->params.pextraType() == PEXTRA_MINIPAGE)
3437 && par->params.pextraHfill())) {
3441 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3442 return par; // ale970302
3447 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3448 BufferParams const & bparams,
3449 ostream & os, TexRow & texrow,
3450 ostream & foot, TexRow & foot_texrow,
3454 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3455 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3456 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3457 "No footnote!" << endl;
3459 LyXParagraph * par = this;
3460 LyXLayout const & style =
3461 textclasslist.Style(bparams.textclass,
3462 previous_->GetLayout());
3464 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3465 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3466 "Float other than footnote in command"
3467 " with moving argument is illegal" << endl;
3470 if (footnotekind != LyXParagraph::FOOTNOTE
3471 && footnotekind != LyXParagraph::MARGIN
3474 // How to solve this?
3475 //&& !suffixIs(file, '\n')
3477 // we need to ensure that real floats like tables and figures
3478 // have their \begin{} on a new line otherwise we can get
3479 // incorrect results when using the endfloat.sty package
3480 // especially if two floats follow one another. ARRae 981022
3481 // NOTE: if the file is length 0 it must have just been
3482 // written out so we assume it ended with a '\n'
3484 // As far as I can see there is never any harm in writing
3485 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3490 bool moving_arg = false;
3491 bool need_closing = false;
3492 bool is_rtl = isRightToLeftPar(bparams);
3494 if (is_rtl != parent_is_rtl) {
3499 need_closing = true;
3502 bool footer_in_body = true;
3503 switch (footnotekind) {
3504 case LyXParagraph::FOOTNOTE:
3505 if (style.intitle) {
3506 os << "\\thanks{\n";
3507 footer_in_body = false;
3510 if (foot_count == -1) {
3511 // we're at depth 0 so we can use:
3512 os << "\\footnote{%\n";
3513 footer_in_body = false;
3515 os << "\\footnotemark{}%\n";
3517 // we only need this when there are
3518 // multiple footnotes
3519 os << "\\stepcounter{footnote}";
3521 os << "\\footnotetext{%\n";
3522 foot_texrow.start(this, 0);
3523 foot_texrow.newline();
3528 case LyXParagraph::MARGIN:
3529 os << "\\marginpar{\n";
3531 case LyXParagraph::FIG:
3532 if (params.pextraType() == PEXTRA_FLOATFLT
3533 && (!params.pextraWidth().empty()
3534 || !params.pextraWidthp().empty())) {
3535 if (!params.pextraWidth().empty())
3536 os << "\\begin{floatingfigure}{"
3537 << params.pextraWidth() << "}\n";
3539 os << "\\begin{floatingfigure}{"
3540 << lyx::atoi(params.pextraWidthp()) / 100.0
3541 << "\\textwidth}\n";
3543 os << "\\begin{figure}";
3544 if (!bparams.float_placement.empty()) {
3545 os << '[' << bparams.float_placement << "]\n";
3551 case LyXParagraph::TAB:
3552 os << "\\begin{table}";
3553 if (!bparams.float_placement.empty()) {
3554 os << '[' << bparams.float_placement << "]\n";
3559 case LyXParagraph::WIDE_FIG:
3560 os << "\\begin{figure*}";
3561 if (!bparams.float_placement.empty()) {
3562 os << '[' << bparams.float_placement << "]\n";
3567 case LyXParagraph::WIDE_TAB:
3568 os << "\\begin{table*}";
3569 if (!bparams.float_placement.empty()) {
3570 os << '[' << bparams.float_placement << "]\n";
3575 case LyXParagraph::ALGORITHM:
3576 os << "\\begin{algorithm}\n";
3581 if (footnotekind != LyXParagraph::FOOTNOTE
3582 || !footer_in_body) {
3583 // Process text for all floats except footnotes in body
3585 LyXLayout const & style =
3587 .Style(bparams.textclass, par->layout);
3589 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3591 if (style.isEnvironment()
3592 || par->params.pextraType() == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3593 // Allows the use of minipages within float
3594 // environments. Shouldn't be circular because
3595 // we don't support footnotes inside
3596 // floats (yet). ARRae
3597 par = par->TeXEnvironment(buf, bparams, os,
3602 par = par->TeXOnePar(buf, bparams,
3603 os, texrow, moving_arg,
3608 if (par && !par->IsDummy() && par->params.depth() > params.depth()) {
3609 par = par->TeXDeeper(buf, bparams, os, texrow,
3613 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3615 // process footnotes > depth 0 or in environments separately
3616 // NOTE: Currently don't support footnotes within footnotes
3617 // even though that is possible using the \footnotemark
3618 std::ostringstream dummy;
3619 TexRow dummy_texrow;
3620 int dummy_count = 0;
3622 LyXLayout const & style =
3624 .Style(bparams.textclass, par->layout);
3626 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3628 if (style.isEnvironment()
3629 || par->params.pextraType() == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3630 // Allows the use of minipages within float
3631 // environments. Shouldn't be circular because
3632 // we don't support footnotes inside
3633 // floats (yet). ARRae
3634 par = par->TeXEnvironment(buf, bparams,
3636 dummy, dummy_texrow,
3639 par = par->TeXOnePar(buf, bparams,
3642 dummy, dummy_texrow,
3646 if (par && !par->IsDummy() && par->params.depth() > params.depth()) {
3647 par = par->TeXDeeper(buf, bparams,
3649 dummy, dummy_texrow,
3653 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3655 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3656 "Footnote in a Footnote -- not supported"
3661 switch (footnotekind) {
3662 case LyXParagraph::FOOTNOTE:
3663 if (footer_in_body) {
3664 // This helps tell which of the multiple
3665 // footnotetexts an error was in.
3667 foot_texrow.newline();
3672 case LyXParagraph::MARGIN:
3675 case LyXParagraph::FIG:
3676 if (params.pextraType() == PEXTRA_FLOATFLT
3677 && (!params.pextraWidth().empty()
3678 || !params.pextraWidthp().empty()))
3679 os << "\\end{floatingfigure}";
3681 os << "\\end{figure}";
3683 case LyXParagraph::TAB:
3684 os << "\\end{table}";
3686 case LyXParagraph::WIDE_FIG:
3687 os << "\\end{figure*}";
3689 case LyXParagraph::WIDE_TAB:
3690 os << "\\end{table*}";
3692 case LyXParagraph::ALGORITHM:
3693 os << "\\end{algorithm}";
3700 if (footnotekind != LyXParagraph::FOOTNOTE
3701 && footnotekind != LyXParagraph::MARGIN) {
3702 // we need to ensure that real floats like tables and figures
3703 // have their \end{} on a line of their own otherwise we can
3704 // get incorrect results when using the endfloat.sty package.
3709 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next_ << endl;
3714 bool LyXParagraph::IsDummy() const
3716 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous_
3717 && previous_->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3721 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
3722 int type, string const & width,
3723 string const & widthp)
3725 params.pextraType(type);
3726 params.pextraWidth(width);
3727 params.pextraWidthp(widthp);
3729 if (textclasslist.Style(bparams.textclass,
3730 layout).isEnvironment()) {
3731 LyXParagraph * par = this;
3732 LyXParagraph * ppar = par;
3734 while (par && (par->layout == layout)
3735 && (par->params.depth() == params.depth())) {
3737 par = par->previous();
3740 par = par->FirstPhysicalPar();
3742 while (par && par->params.depth() > params.depth()) {
3743 par = par->previous();
3746 par = par->FirstPhysicalPar();
3751 while (par && (par->layout == layout)
3752 && (par->params.depth() == params.depth())) {
3753 par->params.pextraType(type);
3754 par->params.pextraWidth(width);
3755 par->params.pextraWidthp(widthp);
3757 par = par->NextAfterFootnote();
3761 if (par && (par->params.depth() > params.depth()))
3762 par->SetPExtraType(bparams,
3763 type, width, widthp);
3765 while (par && ((par->params.depth() > params.depth()) || par->IsDummy()))
3766 par = par->NextAfterFootnote();
3768 while (par && par->params.depth() > params.depth())
3776 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
3778 if (params.pextraType() == PEXTRA_NONE)
3781 params.pextraType(PEXTRA_NONE);
3782 params.pextraWidth(string());
3783 params.pextraWidthp(string());
3785 if (textclasslist.Style(bparams.textclass,
3786 layout).isEnvironment()) {
3787 LyXParagraph * par = this;
3788 LyXParagraph * ppar = par;
3790 while (par && (par->layout == layout)
3791 && (par->params.depth() == params.depth())) {
3793 par = par->previous();
3796 par = par->FirstPhysicalPar();
3798 while (par && par->params.depth() > params.depth()) {
3799 par = par->previous();
3802 par = par->FirstPhysicalPar();
3807 while (par && (par->layout == layout)
3808 && (par->params.depth() == params.depth())) {
3809 par->params.pextraType(PEXTRA_NONE);
3810 par->params.pextraWidth(string());
3811 par->params.pextraWidthp(string());
3813 par = par->NextAfterFootnote();
3817 if (par && (par->params.depth() > params.depth()))
3818 par->UnsetPExtraType(bparams);
3820 while (par && ((par->params.depth() > params.depth()) || par->IsDummy()))
3821 par = par->NextAfterFootnote();
3823 while (par && par->params.depth() > params.depth())
3831 bool LyXParagraph::IsHfill(size_type pos) const
3833 return IsHfillChar(GetChar(pos));
3837 bool LyXParagraph::IsInset(size_type pos) const
3839 return IsInsetChar(GetChar(pos));
3844 bool LyXParagraph::IsFloat(size_type pos) const
3846 return IsFloatChar(GetChar(pos));
3851 bool LyXParagraph::IsNewline(size_type pos) const
3853 return pos >= 0 && IsNewlineChar(GetChar(pos));
3857 bool LyXParagraph::IsSeparator(size_type pos) const
3859 return IsSeparatorChar(GetChar(pos));
3863 bool LyXParagraph::IsLineSeparator(size_type pos) const
3865 return IsLineSeparatorChar(GetChar(pos));
3869 bool LyXParagraph::IsKomma(size_type pos) const
3871 return IsKommaChar(GetChar(pos));
3875 /// Used by the spellchecker
3876 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
3878 value_type const c = GetChar(pos);
3879 if (IsLetterChar(c))
3881 // '\0' is not a letter, allthough every string contains "" (below)
3884 // We want to pass the ' and escape chars to ispell
3885 string const extra = lyxrc.isp_esc_chars + '\'';
3886 char ch[2] = { c, 0 };
3887 return contains(extra, ch);
3891 bool LyXParagraph::IsWord(size_type pos ) const
3893 return IsWordChar(GetChar(pos)) ;
3898 LyXParagraph::getParLanguage(BufferParams const & bparams) const
3902 return FirstPhysicalPar()->getParLanguage(bparams);
3906 return GetFirstFontSettings().language();
3908 return previous_->getParLanguage(bparams);
3910 return bparams.language;
3914 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
3916 return lyxrc.rtl_support
3917 && getParLanguage(bparams)->RightToLeft();
3921 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
3922 Language const * from, Language const * to)
3924 for (size_type i = 0; i < size(); ++i) {
3925 LyXFont font = GetFontSettings(bparams, i);
3926 if (font.language() == from) {
3927 font.setLanguage(to);
3934 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
3936 Language const * doc_language = bparams.language;
3937 for (FontList::const_iterator cit = fontlist.begin();
3938 cit != fontlist.end(); ++cit)
3939 if ((*cit).font().language() != doc_language)
3945 // Convert the paragraph to a string.
3946 // Used for building the table of contents
3947 string const LyXParagraph::String(Buffer const * buffer, bool label)
3949 BufferParams const & bparams = buffer->params;
3952 if (label && !IsDummy() && !params.labelString().empty())
3954 if (label && !params.labelString().empty())
3956 s += params.labelString() + ' ';
3957 string::size_type const len = s.size();
3959 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
3960 value_type c = GetChar(i);
3963 else if (c == META_INSET &&
3964 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
3965 std::ostringstream ost;
3966 GetInset(i)->Ascii(buffer, ost);
3967 s += subst(ost.str().c_str(),'\n',' ');
3972 if (next_ && next_->footnoteflag != LyXParagraph::NO_FOOTNOTE
3973 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
3974 s += NextAfterFootnote()->String(buffer, false);
3978 if (isRightToLeftPar(bparams))
3979 reverse(s.begin() + len,s.end());
3987 string const LyXParagraph::String(Buffer const * buffer,
3988 LyXParagraph::size_type beg,
3989 LyXParagraph::size_type end)
3994 if (beg == 0 && !IsDummy() && !params.labelString().empty())
3996 if (beg == 0 && !params.labelString().empty())
3998 s += params.labelString() + ' ';
4000 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4001 value_type c = GetUChar(buffer->params, i);
4004 else if (c == META_INSET) {
4005 std::ostringstream ost;
4006 GetInset(i)->Ascii(buffer, ost);
4007 s += ost.str().c_str();
4015 void LyXParagraph::SetInsetOwner(Inset * i)
4018 for (InsetList::const_iterator cit = insetlist.begin();
4019 cit != insetlist.end(); ++cit) {
4021 (*cit).inset->setOwner(i);
4026 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4029 for (InsetList::const_iterator cit = insetlist.begin();
4030 cit != insetlist.end(); ++cit) {
4032 if ((*cit).inset->IsTextInset()) {
4033 static_cast<UpdatableInset *>
4034 ((*cit).inset)->deleteLyXText(bv);
4041 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4044 for (InsetList::const_iterator cit = insetlist.begin();
4045 cit != insetlist.end(); ++cit) {
4047 if ((*cit).inset->IsTextInset()) {
4048 static_cast<UpdatableInset *>
4049 ((*cit).inset)->resizeLyXText(bv);
4056 void LyXParagraph::fitToSize()
4058 TextContainer tmp(text.begin(), text.end());
4063 void LyXParagraph::setContentsFromPar(LyXParagraph * par)