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"
26 #include "bufferparams.h"
27 #include "support/FileInfo.h"
28 #include "support/LAssert.h"
30 #include "LaTeXFeatures.h"
31 #include "insets/insetinclude.h"
32 #include "insets/insetbib.h"
33 #include "insets/insettext.h"
34 #include "support/filetools.h"
35 #include "lyx_gui_misc.h"
37 #include "support/lyxmanip.h"
38 #include "BufferView.h"
45 using std::lower_bound;
46 using std::upper_bound;
49 int tex_code_break_column = 72; // needs non-zero initialization. set later.
50 // this is a bad idea, but how can LyXParagraph find its buffer to get
51 // parameters? (JMarc)
52 extern BufferView * current_view;
53 extern string bibitemWidest(BufferView *);
55 // this is a minibuffer
56 static char minibuffer_char;
57 static LyXFont minibuffer_font;
58 static Inset * minibuffer_inset;
61 // Initialization of the counter for the paragraph id's,
62 // declared in lyxparagraph.h
63 unsigned int LyXParagraph::paragraph_id = 0;
66 LyXParagraph::LyXParagraph()
68 text.reserve(500); // is this number too big?
70 for (int i = 0; i < 10; ++i) setCounter(i , 0);
77 footnoteflag = LyXParagraph::NO_FOOTNOTE;
78 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
80 align = LYX_ALIGN_BLOCK;
83 /* table stuff -- begin*/
85 /* table stuff -- end*/
89 bibkey = 0; // ale970302
94 // This konstruktor inserts the new paragraph in a list.
95 LyXParagraph::LyXParagraph(LyXParagraph * par)
98 par->text.resize(par->text.size());
100 for (int i = 0; i < 10; ++i) setCounter(i, 0);
104 // double linked list begin
107 next->previous = this;
109 previous->next = this;
112 footnoteflag = LyXParagraph::NO_FOOTNOTE;
113 footnotekind = LyXParagraph::FOOTNOTE;
116 /* table stuff -- begin*/
118 /* table stuff -- end*/
121 id_ = paragraph_id++;
123 bibkey = 0; // ale970302
129 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
130 BufferParams const & params,
131 char footflag, char dth) const
133 LyXFont font1, font2;
138 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
140 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
142 // The beginning or the end of a footnote environment?
143 if (footflag != footnoteflag) {
144 footflag = footnoteflag;
146 os << "\n\\begin_float "
147 << string_footnotekinds[footnotekind]
150 os << "\n\\end_float ";
154 // The beginning or end of a deeper (i.e. nested) area?
157 while (depth > dth) {
158 os << "\n\\begin_deeper ";
162 while (depth < dth) {
163 os << "\n\\end_deeper ";
169 // First write the layout
171 << textclasslist.NameOfLayout(params.textclass, layout)
174 // Maybe some vertical spaces.
175 if (added_space_top.kind() != VSpace::NONE)
176 os << "\\added_space_top "
177 << added_space_top.asLyXCommand() << " ";
178 if (added_space_bottom.kind() != VSpace::NONE)
179 os << "\\added_space_bottom "
180 << added_space_bottom.asLyXCommand() << " ";
182 // Maybe the paragraph has special spacing
183 spacing.writeFile(os, true);
185 // The labelwidth string used in lists.
186 if (!labelwidthstring.empty())
187 os << "\\labelwidthstring "
188 << labelwidthstring << '\n';
190 // Lines above or below?
194 os << "\\line_bottom ";
196 // Pagebreaks above or below?
198 os << "\\pagebreak_top ";
199 if (pagebreak_bottom)
200 os << "\\pagebreak_bottom ";
202 // Start of appendix?
203 if (start_of_appendix)
204 os << "\\start_of_appendix ";
211 if (align != LYX_ALIGN_LAYOUT) {
213 case LYX_ALIGN_LEFT: h = 1; break;
214 case LYX_ALIGN_RIGHT: h = 2; break;
215 case LYX_ALIGN_CENTER: h = 3; break;
216 default: h = 0; break;
218 os << "\\align " << string_align[h] << " ";
220 if (pextra_type != PEXTRA_NONE) {
221 os << "\\pextra_type " << pextra_type;
222 if (pextra_type == PEXTRA_MINIPAGE) {
223 os << " \\pextra_alignment "
226 os << " \\pextra_hfill "
228 if (pextra_start_minipage)
229 os << " \\pextra_start_minipage "
230 << pextra_start_minipage;
232 if (!pextra_width.empty()) {
233 os << " \\pextra_width "
234 << VSpace(pextra_width).asLyXCommand();
235 } else if (!pextra_widthp.empty()) {
236 os << " \\pextra_widthp "
242 // Dummy layout. This means that a footnote ended.
243 os << "\n\\end_float ";
244 footflag = LyXParagraph::NO_FOOTNOTE;
247 // It might be a table.
249 os << "\\LyXTable\n";
255 bibkey->Write(buf, os);
257 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
260 for (size_type i = 0; i < size(); ++i) {
266 // Write font changes
267 font2 = GetFontSettings(params, i);
268 if (font2 != font1) {
269 font2.lyxWriteChanges(font1, os);
278 Inset const * inset = GetInset(i);
280 if (inset->DirectWrite()) {
281 // international char, let it write
282 // code directly so it's shorter in
284 inset->Write(buf, os);
286 os << "\n\\begin_inset ";
287 inset->Write(buf, os);
288 os << "\n\\end_inset \n\n";
294 os << "\n\\newline \n";
298 os << "\n\\hfill \n";
302 os << "\n\\backslash \n";
306 if (i + 1 < size() && GetChar(i + 1) == ' ') {
313 if ((column > 70 && c == ' ')
318 // this check is to amend a bug. LyX sometimes
319 // inserts '\0' this could cause problems.
323 lyxerr << "ERROR (LyXParagraph::writeFile):"
324 " NULL char in structure." << endl;
330 // now write the next paragraph
332 next->writeFile(buf, os, params, footflag, dth);
336 void LyXParagraph::validate(LaTeXFeatures & features) const
338 BufferParams const & params = features.bufferParams();
340 // this will be useful later
341 LyXLayout const & layout =
342 textclasslist.Style(params.textclass,
346 if (line_top || line_bottom)
347 features.lyxline = true;
348 if (!spacing.isDefault())
349 features.setspace = true;
352 features.layout[GetLayout()] = true;
355 Language const * doc_language = params.language_info;
357 for (FontList::const_iterator cit = fontlist.begin();
358 cit != fontlist.end(); ++cit) {
359 if ((*cit).font.noun() == LyXFont::ON) {
360 lyxerr[Debug::LATEX] << "font.noun: "
361 << (*cit).font.noun()
363 features.noun = true;
364 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
365 << (*cit).font.stateText(0)
368 switch ((*cit).font.color()) {
370 case LColor::inherit:
374 features.color = true;
375 lyxerr[Debug::LATEX] << "Color enabled. Font: "
376 << (*cit).font.stateText(0)
380 Language const * language = (*cit).font.language();
381 if (language != doc_language) {
382 features.UsedLanguages.insert(language);
383 lyxerr[Debug::LATEX] << "Found language "
384 << language->lang() << endl;
389 for (InsetList::const_iterator cit = insetlist.begin();
390 cit != insetlist.end(); ++cit) {
392 (*cit).inset->Validate(features);
395 if (table && table->IsLongTable())
396 features.longtable = true;
397 if (pextra_type == PEXTRA_INDENT)
398 features.LyXParagraphIndent = true;
399 if (pextra_type == PEXTRA_FLOATFLT)
400 features.floatflt = true;
401 if (layout.needprotect
402 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
403 features.NeedLyXFootnoteCode = true;
404 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
405 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
406 features.NeedLyXMinipageIndent = true;
407 if (table && table->NeedRotating())
408 features.rotating = true;
409 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
410 features.algorithm = true;
414 // First few functions needed for cut and paste and paragraph breaking.
415 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
416 LyXParagraph::size_type pos) const
418 minibuffer_char = GetChar(pos);
419 minibuffer_font = GetFontSettings(bparams, pos);
420 minibuffer_inset = 0;
421 if (minibuffer_char == LyXParagraph::META_INSET) {
423 minibuffer_inset = GetInset(pos)->Clone();
425 minibuffer_inset = 0;
426 minibuffer_char = ' ';
427 // This reflects what GetInset() does (ARRae)
433 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
434 LyXParagraph::size_type pos)
436 minibuffer_char = GetChar(pos);
437 minibuffer_font = GetFontSettings(bparams, pos);
438 minibuffer_inset = 0;
439 if (minibuffer_char == LyXParagraph::META_INSET) {
441 minibuffer_inset = GetInset(pos);
442 // This is a little hack since I want exactly
443 // the inset, not just a clone. Otherwise
444 // the inset would be deleted when calling Erase(pos)
446 InsetList::iterator it = lower_bound(insetlist.begin(),
449 if (it != insetlist.end() && (*it).pos == pos)
452 minibuffer_inset = 0;
453 minibuffer_char = ' ';
454 // This reflects what GetInset() does (ARRae)
459 // Erase(pos); now the caller is responsible for that.
463 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
465 if ((minibuffer_char == LyXParagraph::META_INSET) &&
466 !InsertInsetAllowed(minibuffer_inset))
468 if (minibuffer_char == LyXParagraph::META_INSET)
469 InsertInset(pos, minibuffer_inset, minibuffer_font);
471 InsertChar(pos, minibuffer_char, minibuffer_font);
479 void LyXParagraph::Clear()
484 pagebreak_top = false;
485 pagebreak_bottom = false;
487 added_space_top = VSpace(VSpace::NONE);
488 added_space_bottom = VSpace(VSpace::NONE);
489 spacing.set(Spacing::Default);
491 align = LYX_ALIGN_LAYOUT;
495 pextra_type = PEXTRA_NONE;
496 pextra_width.erase();
497 pextra_widthp.erase();
498 pextra_alignment = MINIPAGE_ALIGN_TOP;
499 pextra_hfill = false;
500 pextra_start_minipage = false;
503 labelwidthstring.erase();
507 start_of_appendix = false;
511 // the destructor removes the new paragraph from the list
512 LyXParagraph::~LyXParagraph()
515 previous->next = next;
517 next->previous = previous;
519 for (InsetList::iterator it = insetlist.begin();
520 it != insetlist.end(); ++it) {
524 /* table stuff -- begin*/
526 /* table stuff -- end*/
532 //lyxerr << "LyXParagraph::paragraph_id = "
533 // << LyXParagraph::paragraph_id << endl;
537 void LyXParagraph::Erase(LyXParagraph::size_type pos)
539 // > because last is the next unused position, and you can
540 // use it if you want
543 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
544 NextAfterFootnote()->Erase(pos - text.size() - 1);
547 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
548 "position does not exist." << endl;
551 if (pos < size()) { // last is free for insertation, but should be empty
552 // if it is an inset, delete the inset entry
553 if (text[pos] == LyXParagraph::META_INSET) {
555 InsetList::iterator it = lower_bound(insetlist.begin(),
558 if (it != insetlist.end() && (*it).pos == pos) {
563 text.erase(text.begin() + pos);
565 // Erase entries in the tables.
566 FontList::iterator it = lower_bound(fontlist.begin(),
569 if (it != fontlist.end() && (*it).pos == pos &&
571 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
572 // If it is a multi-character font
573 // entry, we just make it smaller
574 // (see update below), otherwise we
576 unsigned int i = it - fontlist.begin();
577 fontlist.erase(fontlist.begin() + i);
578 it = fontlist.begin() + i;
579 if (i > 0 && i < fontlist.size() &&
580 fontlist[i-1].font == fontlist[i].font) {
581 fontlist.erase(fontlist.begin() + i-1);
582 it = fontlist.begin() + i-1;
586 // Update all other entries.
587 for (; it != fontlist.end(); ++it)
590 // Update the inset table.
591 for (InsetList::iterator it = upper_bound(insetlist.begin(),
594 it != insetlist.end(); ++it)
597 lyxerr << "ERROR (LyXParagraph::Erase): "
598 "can't erase non-existant char." << endl;
603 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
605 LyXFont f(LyXFont::ALL_INHERIT);
606 InsertChar(pos, c, f);
610 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
611 char c, LyXFont const & font)
613 // > because last is the next unused position, and you can
614 // use it if you want
618 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
619 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
623 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
624 "position does not exist." << endl;
627 text.insert(text.begin() + pos, c);
628 // Update the font table.
629 for (FontList::iterator it = lower_bound(fontlist.begin(),
632 it != fontlist.end(); ++it)
635 // Update the inset table.
636 for (InsetList::iterator it = lower_bound(insetlist.begin(),
639 it != insetlist.end(); ++it)
646 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
649 LyXFont f(LyXFont::ALL_INHERIT);
650 InsertInset(pos, inset, f);
654 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
655 Inset * inset, LyXFont const & font)
659 // > because last is the next unused position, and you can
660 // use it if you want
664 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
666 ->InsertInset(pos - text.size() - 1,
670 lyxerr << "ERROR (LyXParagraph::InsertInset): "
671 "position does not exist: " << pos << endl;
675 InsertChar(pos, META_INSET, font);
676 Assert(text[pos] == META_INSET);
678 // Add a new entry in the inset table.
679 InsetList::iterator it = lower_bound(insetlist.begin(),
682 if (it != insetlist.end() && (*it).pos == pos)
683 lyxerr << "ERROR (LyXParagraph::InsertInset): "
684 "there is an inset in position: " << pos << endl;
686 insetlist.insert(it, InsetTable(pos, inset));
688 inset->setOwner(inset_owner);
692 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
694 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
697 return inset_owner->InsertInsetAllowed(inset);
702 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
707 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
708 return NextAfterFootnote()
709 ->GetInset(pos - text.size() - 1);
712 lyxerr << "ERROR (LyXParagraph::GetInset): "
713 "position does not exist: "
719 InsetList::iterator it = lower_bound(insetlist.begin(),
722 if (it != insetlist.end() && (*it).pos == pos)
725 lyxerr << "ERROR (LyXParagraph::GetInset): "
726 "Inset does not exist: " << pos << endl;
729 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
730 // Did this commenting out introduce a bug? So far I have not
731 // see any, please enlighten me. (Lgb)
732 // My guess is that since the inset does not exist, we might
733 // as well replace it with a space to prevent craches. (Asger)
738 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
743 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
744 return NextAfterFootnote()
745 ->GetInset(pos - text.size() - 1);
748 lyxerr << "ERROR (LyXParagraph::GetInset): "
749 "position does not exist: "
755 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
758 if (cit != insetlist.end() && (*cit).pos == pos)
761 lyxerr << "ERROR (LyXParagraph::GetInset): "
762 "Inset does not exist: " << pos << endl;
764 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
765 // Did this commenting out introduce a bug? So far I have not
766 // see any, please enlighten me. (Lgb)
767 // My guess is that since the inset does not exist, we might
768 // as well replace it with a space to prevent craches. (Asger)
773 // Gets uninstantiated font setting at position.
774 // Optimized after profiling. (Asger)
775 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
776 LyXParagraph::size_type pos) const
779 FontList::const_iterator cit = lower_bound(fontlist.begin(),
782 if (cit != fontlist.end())
785 // > because last is the next unused position, and you can
786 // use it if you want
787 else if (pos > size()) {
790 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
791 return NextAfterFootnote()
792 ->GetFontSettings(bparams,
793 pos - text.size() - 1);
796 // Why is it an error to ask for the font of a
797 // position that does not exist? Would it be
798 // enough for this to be enabled on debug?
799 // We want strict error checking, but it's ok to only
800 // have it when debugging. (Asger)
801 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
802 "position does not exist. "
803 << pos << " (" << static_cast<int>(pos)
805 } else if (pos > 0) {
806 return GetFontSettings(bparams, pos - 1);
807 } else // pos = size() = 0
808 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
810 return LyXFont(LyXFont::ALL_INHERIT);
813 // Gets uninstantiated font setting at position 0
814 LyXFont LyXParagraph::GetFirstFontSettings() const
817 if (!fontlist.empty())
818 return fontlist[0].font;
822 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
823 return NextAfterFootnote()->GetFirstFontSettings();
825 return LyXFont(LyXFont::ALL_INHERIT);
829 // Gets the fully instantiated font at a given position in a paragraph
830 // This is basically the same function as LyXText::GetFont() in text2.C.
831 // The difference is that this one is used for generating the LaTeX file,
832 // and thus cosmetic "improvements" are disallowed: This has to deliver
833 // the true picture of the buffer. (Asger)
834 // If position is -1, we get the layout font of the paragraph.
835 // If position is -2, we get the font of the manual label of the paragraph.
836 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
837 LyXParagraph::size_type pos) const
840 LyXLayout const & layout =
841 textclasslist.Style(bparams.textclass,
843 LyXParagraph::size_type main_body = 0;
844 if (layout.labeltype == LABEL_MANUAL)
845 main_body = BeginningOfMainBody();
850 layoutfont = layout.labelfont;
852 layoutfont = layout.font;
853 tmpfont = GetFontSettings(bparams, pos);
854 tmpfont.realize(layoutfont);
856 // process layoutfont for pos == -1 and labelfont for pos < -1
858 tmpfont = layout.font;
860 tmpfont = layout.labelfont;
861 tmpfont.setLanguage(getParLanguage(bparams));
864 // check for environment font information
865 char par_depth = GetDepth();
866 LyXParagraph const * par = this;
867 while (par && par_depth && !tmpfont.resolved()) {
868 par = par->DepthHook(par_depth - 1);
870 tmpfont.realize(textclasslist.
871 Style(bparams.textclass,
872 par->GetLayout()).font);
873 par_depth = par->GetDepth();
877 tmpfont.realize(textclasslist
878 .TextClass(bparams.textclass)
884 /// Returns the height of the highest font in range
886 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
887 LyXParagraph::size_type endpos) const
889 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
890 if (fontlist.empty())
893 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
896 if (end_it != fontlist.end())
899 for (FontList::const_iterator cit = lower_bound(fontlist.begin(),
901 startpos, matchFT());
902 cit != end_it; ++cit) {
903 LyXFont::FONT_SIZE size = (*cit).font.size();
904 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
911 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
918 // > because last is the next unused position, and you can
919 // use it if you want
920 else if (pos > size()) {
922 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
923 return NextAfterFootnote()
924 ->GetChar(pos - text.size() - 1);
928 lyxerr << "ERROR (LyXParagraph::GetChar): "
929 "position does not exist."
930 << pos << " (" << static_cast<int>(pos)
932 // Assert(false); // This triggers sometimes...
941 // We should have a footnote environment.
942 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
943 // Notice that LyX does request the
944 // last char from time to time. (Asger)
945 //lyxerr << "ERROR (LyXParagraph::GetChar): "
946 // "expected footnote." << endl;
949 switch (next->footnotekind) {
950 case LyXParagraph::FOOTNOTE:
951 return LyXParagraph::META_FOOTNOTE;
952 case LyXParagraph::MARGIN:
953 return LyXParagraph::META_MARGIN;
954 case LyXParagraph::FIG:
955 case LyXParagraph::WIDE_FIG:
956 return LyXParagraph::META_FIG;
957 case LyXParagraph::TAB:
958 case LyXParagraph::WIDE_TAB:
959 return LyXParagraph::META_TAB;
960 case LyXParagraph::ALGORITHM:
961 return LyXParagraph::META_ALGORITHM;
963 return '\0'; // to shut up gcc
969 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
976 // > because last is the next unused position, and you can
977 // use it if you want
978 else if (pos > size()) {
980 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
981 return NextAfterFootnote()
982 ->GetChar(pos - text.size() - 1);
986 lyxerr << "ERROR (LyXParagraph::GetChar const): "
987 "position does not exist."
988 << pos << " (" << static_cast<int>(pos)
996 // We should have a footnote environment.
997 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
998 // Notice that LyX does request the
999 // last char from time to time. (Asger)
1000 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1001 // "expected footnote." << endl;
1004 switch (next->footnotekind) {
1005 case LyXParagraph::FOOTNOTE:
1006 return LyXParagraph::META_FOOTNOTE;
1007 case LyXParagraph::MARGIN:
1008 return LyXParagraph::META_MARGIN;
1009 case LyXParagraph::FIG:
1010 case LyXParagraph::WIDE_FIG:
1011 return LyXParagraph::META_FIG;
1012 case LyXParagraph::TAB:
1013 case LyXParagraph::WIDE_TAB:
1014 return LyXParagraph::META_TAB;
1015 case LyXParagraph::ALGORITHM:
1016 return LyXParagraph::META_ALGORITHM;
1018 return '\0'; // to shut up gcc
1024 // return an string of the current word, and the end of the word in lastpos.
1025 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1029 // the current word is defined as starting at the first character
1030 // from the immediate left of lastpospos which meets the definition
1031 // of IsLetter(), continuing to the last character to the right
1032 // of this meeting IsLetter.
1038 // move back until we have a letter
1040 //there's no real reason to have firstpos & lastpos as
1041 //separate variables as this is written, but maybe someon
1042 // will want to return firstpos in the future.
1044 //since someone might have typed a punctuation first
1045 int firstpos = lastpos;
1047 while ((firstpos >= 0) && !IsLetter(firstpos))
1050 // now find the beginning by looking for a nonletter
1052 while ((firstpos>= 0) && IsLetter(firstpos))
1055 // the above is now pointing to the preceeding non-letter
1059 // so copy characters into theword until we get a nonletter
1060 // note that this can easily exceed lastpos, wich means
1061 // that if used in the middle of a word, the whole word
1064 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1071 LyXParagraph::size_type LyXParagraph::Last() const
1074 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1075 return text.size() + NextAfterFootnote()->Last() + 1;
1076 // the 1 is the symbol
1084 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1086 // > because last is the next unused position, and you can
1087 // use it if you want
1091 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1092 return NextAfterFootnote()
1093 ->ParFromPos(pos - text.size() - 1);
1096 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1097 "position does not exist." << endl;
1104 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1106 // > because last is the next unused position, and you can
1107 // use it if you want
1111 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1112 return NextAfterFootnote()
1113 ->PositionInParFromPos(pos - text.size() - 1);
1117 "ERROR (LyXParagraph::PositionInParFromPos): "
1118 "position does not exist." << endl;
1126 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1127 LyXFont const & font)
1129 // > because last is the next unused position, and you can
1130 // use it if you want
1134 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1135 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1139 lyxerr << "ERROR (LyXParagraph::SetFont): "
1140 "position does not exist." << endl;
1145 // First, reduce font against layout/label font
1146 // Update: The SetCharFont() routine in text2.C already
1147 // reduces font, so we don't need to do that here. (Asger)
1148 // No need to simplify this because it will disappear
1149 // in a new kernel. (Asger)
1150 // Next search font table
1152 FontList::iterator it = lower_bound(fontlist.begin(),
1155 unsigned int i = it - fontlist.begin();
1156 bool notfound = it == fontlist.end();
1158 if (!notfound && fontlist[i].font == font)
1161 bool begin = pos == 0 || notfound ||
1162 (i > 0 && fontlist[i-1].pos == pos - 1);
1163 // Is position pos is a beginning of a font block?
1164 bool end = !notfound && fontlist[i].pos == pos;
1165 // Is position pos is the end of a font block?
1166 if (begin && end) { // A single char block
1167 if (i+1 < fontlist.size() &&
1168 fontlist[i+1].font == font) {
1169 // Merge the singleton block with the next block
1170 fontlist.erase(fontlist.begin() + i);
1171 if (i > 0 && fontlist[i-1].font == font)
1172 fontlist.erase(fontlist.begin() + i-1);
1173 } else if (i > 0 && fontlist[i-1].font == font) {
1174 // Merge the singleton block with the previous block
1175 fontlist[i-1].pos = pos;
1176 fontlist.erase(fontlist.begin() + i);
1178 fontlist[i].font = font;
1180 if (i > 0 && fontlist[i-1].font == font)
1181 fontlist[i-1].pos = pos;
1183 fontlist.insert(fontlist.begin() + i,
1184 FontTable(pos, font));
1186 fontlist[i].pos = pos - 1;
1187 if (!(i+1 < fontlist.size() &&
1188 fontlist[i+1].font == font))
1189 fontlist.insert(fontlist.begin() + i+1,
1190 FontTable(pos, font));
1191 } else { // The general case. The block is splitted into 3 blocks
1192 fontlist.insert(fontlist.begin() + i,
1193 FontTable(pos - 1, fontlist[i].font));
1194 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1199 // This function is able to hide closed footnotes.
1200 LyXParagraph * LyXParagraph::Next()
1203 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1204 LyXParagraph * tmp = next;
1206 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1208 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1209 return tmp->Next(); /* there can be more than one
1210 footnote in a logical
1213 return next; // This should never happen!
1220 LyXParagraph * LyXParagraph::NextAfterFootnote()
1223 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1224 LyXParagraph * tmp = next;
1225 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1227 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1228 return tmp; /* there can be more than one footnote
1229 in a logical paragraph */
1231 return next; // This should never happen!
1238 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1241 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1242 LyXParagraph * tmp = next;
1243 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1245 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1246 return tmp; /* there can be more than one footnote
1247 in a logical paragraph */
1249 return next; // This should never happen!
1256 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1260 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1262 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1263 tmp = tmp->previous;
1264 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1265 return tmp; /* there can be more than one footnote
1266 in a logical paragraph */
1268 return previous; // This should never happen!
1275 LyXParagraph * LyXParagraph::LastPhysicalPar()
1278 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1281 LyXParagraph * tmp = this;
1283 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1284 tmp = tmp->NextAfterFootnote();
1292 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1295 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1298 LyXParagraph const * tmp = this;
1300 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1301 tmp = tmp->NextAfterFootnote();
1309 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1314 LyXParagraph * tmppar = this;
1318 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1319 tmppar = tmppar->previous;
1331 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1336 LyXParagraph const * tmppar = this;
1340 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1341 tmppar = tmppar->previous;
1353 // This function is able to hide closed footnotes.
1354 LyXParagraph * LyXParagraph::Previous()
1356 LyXParagraph * tmp = previous;
1362 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1363 tmp = tmp->previous;
1365 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1366 tmp = tmp->previous;
1367 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1368 return tmp->next->Previous();
1378 // This function is able to hide closed footnotes.
1379 LyXParagraph const * LyXParagraph::Previous() const
1381 LyXParagraph * tmp = previous;
1386 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1387 tmp = tmp->previous;
1389 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1390 tmp = tmp->previous;
1391 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1392 return tmp->next->Previous();
1402 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1403 LyXParagraph::size_type pos,
1406 size_type i, j, pos_end, pos_first;
1407 // create a new paragraph
1408 LyXParagraph * par = ParFromPos(pos);
1409 LyXParagraph * firstpar = FirstPhysicalPar();
1411 LyXParagraph * tmp = new LyXParagraph(par);
1414 tmp->footnoteflag = footnoteflag;
1415 tmp->footnotekind = footnotekind;
1417 // this is an idea for a more userfriendly layout handling, I will
1418 // see what the users say
1420 // layout stays the same with latex-environments
1422 tmp->SetOnlyLayout(bparams, firstpar->layout);
1423 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1426 if (Last() > pos || !Last() || flag == 2) {
1427 tmp->SetOnlyLayout(bparams, firstpar->layout);
1428 tmp->align = firstpar->align;
1429 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1431 tmp->line_bottom = firstpar->line_bottom;
1432 firstpar->line_bottom = false;
1433 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1434 firstpar->pagebreak_bottom = false;
1435 tmp->added_space_bottom = firstpar->added_space_bottom;
1436 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1438 tmp->depth = firstpar->depth;
1439 tmp->noindent = firstpar->noindent;
1441 // copy everything behind the break-position
1442 // to the new paragraph
1444 while (ParFromPos(pos_first) != par)
1447 pos_end = pos_first + par->text.size() - 1;
1449 for (i = j = pos; i <= pos_end; ++i) {
1450 par->CutIntoMinibuffer(bparams, i - pos_first);
1451 if (tmp->InsertFromMinibuffer(j - pos))
1454 tmp->text.resize(tmp->text.size());
1455 for (i = pos_end; i >= pos; --i)
1456 par->Erase(i - pos_first);
1458 par->text.resize(par->text.size());
1461 // just an idea of me
1463 tmp->line_top = firstpar->line_top;
1464 tmp->pagebreak_top = firstpar->pagebreak_top;
1465 tmp->added_space_top = firstpar->added_space_top;
1466 tmp->bibkey = firstpar->bibkey;
1468 // layout stays the same with latex-environments
1470 firstpar->SetOnlyLayout(bparams, tmp->layout);
1471 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1472 firstpar->depth = tmp->depth;
1478 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1480 par = par->FirstPhysicalPar();
1482 footnoteflag = par->footnoteflag;
1483 footnotekind = par->footnotekind;
1485 layout = par->layout;
1486 align = par-> align;
1487 SetLabelWidthString(par->labelwidthstring);
1489 line_bottom = par->line_bottom;
1490 pagebreak_bottom = par->pagebreak_bottom;
1491 added_space_bottom = par->added_space_bottom;
1493 line_top = par->line_top;
1494 pagebreak_top = par->pagebreak_top;
1495 added_space_top = par->added_space_top;
1497 spacing = par->spacing;
1499 pextra_type = par->pextra_type;
1500 pextra_width = par->pextra_width;
1501 pextra_widthp = par->pextra_widthp;
1502 pextra_alignment = par->pextra_alignment;
1503 pextra_hfill = par->pextra_hfill;
1504 pextra_start_minipage = par->pextra_start_minipage;
1506 noindent = par->noindent;
1512 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1514 LyXParagraph * tmppar = this;
1517 && tmppar->previous->footnoteflag ==
1518 LyXParagraph::CLOSED_FOOTNOTE)
1519 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1520 tmppar = tmppar->previous;
1523 return this; // This should never happen!
1530 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1532 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1536 if (!IsDummy() && !table){
1538 && (IsNewline(0) || IsLineSeparator(0))){
1547 LyXParagraph * LyXParagraph::Clone() const
1549 // create a new paragraph
1550 LyXParagraph * result = new LyXParagraph;
1552 result->MakeSameLayout(this);
1554 // this is because of the dummy layout of the paragraphs that
1556 result->layout = layout;
1559 /* table stuff -- begin*/
1561 result->table = table->Clone();
1564 /* table stuff -- end*/
1566 result->inset_owner = inset_owner;
1569 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1572 // copy everything behind the break-position to the new paragraph
1574 result->text = text;
1575 result->fontlist = fontlist;
1576 result->insetlist = insetlist;
1577 for (InsetList::iterator it = result->insetlist.begin();
1578 it != result->insetlist.end(); ++it)
1579 (*it).inset = (*it).inset->Clone();
1584 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1586 par = par->FirstPhysicalPar();
1590 par->footnoteflag == footnoteflag &&
1591 par->footnotekind == footnotekind &&
1593 par->layout == layout &&
1595 par->align == align &&
1597 par->line_bottom == line_bottom &&
1598 par->pagebreak_bottom == pagebreak_bottom &&
1599 par->added_space_bottom == added_space_bottom &&
1601 par->line_top == line_top &&
1602 par->pagebreak_top == pagebreak_top &&
1603 par->added_space_top == added_space_top &&
1605 par->spacing == spacing &&
1607 par->pextra_type == pextra_type &&
1608 par->pextra_width == pextra_width &&
1609 par->pextra_widthp == pextra_widthp &&
1610 par->pextra_alignment == pextra_alignment &&
1611 par->pextra_hfill == pextra_hfill &&
1612 par->pextra_start_minipage == pextra_start_minipage &&
1614 par->table == table && // what means: NO TABLE AT ALL
1617 par->noindent == noindent &&
1618 par->depth == depth);
1622 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1623 LyXParagraph::size_type pos)
1625 // create a new paragraph
1626 LyXParagraph * par = ParFromPos(pos);
1628 LyXParagraph * tmp = new LyXParagraph(par);
1630 tmp->MakeSameLayout(par);
1632 // When can pos < Last()?
1633 // I guess pos == Last() is possible.
1635 // copy everything behind the break-position to the new
1637 size_type pos_first = 0;
1638 while (ParFromPos(pos_first) != par)
1640 size_type pos_end = pos_first + par->text.size() - 1;
1643 for (i = j = pos; i <= pos_end; ++i) {
1644 par->CutIntoMinibuffer(bparams, i - pos_first);
1645 if (tmp->InsertFromMinibuffer(j - pos))
1648 tmp->text.resize(tmp->text.size());
1649 for (size_type i = pos_end; i >= pos; --i)
1650 par->Erase(i - pos_first);
1652 par->text.resize(par->text.size());
1657 // Be carefull, this does not make any check at all.
1658 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1660 // copy the next paragraph to this one
1661 LyXParagraph * the_next = Next();
1663 LyXParagraph * firstpar = FirstPhysicalPar();
1665 // first the DTP-stuff
1666 firstpar->line_bottom = the_next->line_bottom;
1667 firstpar->added_space_bottom = the_next->added_space_bottom;
1668 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1670 size_type pos_end = the_next->text.size() - 1;
1671 size_type pos_insert = Last();
1673 // ok, now copy the paragraph
1675 for (i = j = 0; i <= pos_end; ++i) {
1676 the_next->CutIntoMinibuffer(bparams, i);
1677 if (InsertFromMinibuffer(pos_insert + j))
1681 // delete the next paragraph
1682 LyXParagraph * ppar = the_next->previous;
1683 LyXParagraph * npar = the_next->next;
1690 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1692 LyXParagraph * par = ParFromPos(pos);
1694 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1695 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1701 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1703 LyXParagraph * par = ParFromPos(pos);
1705 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1706 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1712 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1714 LyXParagraph const * par = this;
1715 int par_depth = GetDepth();
1717 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1719 textclasslist.Style(bparams.textclass,
1720 layout).endlabeltype;
1721 if (endlabeltype != END_LABEL_NO_LABEL) {
1722 LyXParagraph const * last = this;
1723 if( footnoteflag == NO_FOOTNOTE)
1724 last = LastPhysicalPar();
1725 else if (next->footnoteflag == NO_FOOTNOTE)
1726 return endlabeltype;
1728 if (!last || !last->next)
1729 return endlabeltype;
1731 int next_depth = last->next->GetDepth();
1732 if (par_depth > next_depth ||
1733 (par_depth == next_depth && layout != last->next->GetLayout() ))
1734 return endlabeltype;
1739 par = par->DepthHook(par_depth - 1);
1741 par_depth = par->GetDepth();
1743 return END_LABEL_NO_LABEL;
1747 LyXTextClass::size_type LyXParagraph::GetLayout() const
1749 return FirstPhysicalPar()->layout;
1753 char LyXParagraph::GetDepth() const
1755 return FirstPhysicalPar()->depth;
1759 char LyXParagraph::GetAlign() const
1761 return FirstPhysicalPar()->align;
1765 string LyXParagraph::GetLabelstring() const
1767 return FirstPhysicalPar()->labelstring;
1771 int LyXParagraph::GetFirstCounter(int i) const
1773 return FirstPhysicalPar()->counter_[i];
1777 // the next two functions are for the manual labels
1778 string LyXParagraph::GetLabelWidthString() const
1780 if (!FirstPhysicalPar()->labelwidthstring.empty())
1781 return FirstPhysicalPar()->labelwidthstring;
1783 return _("Senseless with this layout!");
1787 void LyXParagraph::SetLabelWidthString(string const & s)
1789 LyXParagraph * par = FirstPhysicalPar();
1791 par->labelwidthstring = s;
1795 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1796 LyXTextClass::size_type new_layout)
1798 LyXParagraph * par = FirstPhysicalPar();
1799 LyXParagraph * ppar = 0;
1800 LyXParagraph * npar = 0;
1802 par->layout = new_layout;
1804 /* table stuff -- begin*/
1807 /* table stuff -- end*/
1809 if (par->pextra_type == PEXTRA_NONE) {
1810 if (par->Previous()) {
1811 ppar = par->Previous()->FirstPhysicalPar();
1814 && (ppar->depth > par->depth))
1815 ppar = ppar->Previous()->FirstPhysicalPar();
1818 npar = par->Next()->NextAfterFootnote();
1821 && (npar->depth > par->depth))
1822 npar = npar->Next()->NextAfterFootnote();
1824 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1826 p1 = ppar->pextra_width,
1827 p2 = ppar->pextra_widthp;
1828 ppar->SetPExtraType(bparams, ppar->pextra_type,
1829 p1.c_str(), p2.c_str());
1831 if ((par->pextra_type == PEXTRA_NONE) &&
1832 npar && (npar->pextra_type != PEXTRA_NONE)) {
1834 p1 = npar->pextra_width,
1835 p2 = npar->pextra_widthp;
1836 npar->SetPExtraType(bparams, npar->pextra_type,
1837 p1.c_str(), p2.c_str());
1843 void LyXParagraph::SetLayout(BufferParams const & bparams,
1844 LyXTextClass::size_type new_layout)
1847 * par = FirstPhysicalPar(),
1851 par->layout = new_layout;
1852 par->labelwidthstring.erase();
1853 par->align = LYX_ALIGN_LAYOUT;
1854 par->added_space_top = VSpace(VSpace::NONE);
1855 par->added_space_bottom = VSpace(VSpace::NONE);
1856 par->spacing.set(Spacing::Default);
1859 /* table stuff -- begin*/
1862 /* table stuff -- end*/
1864 if (par->pextra_type == PEXTRA_NONE) {
1865 if (par->Previous()) {
1866 ppar = par->Previous()->FirstPhysicalPar();
1869 && (ppar->depth > par->depth))
1870 ppar = ppar->Previous()->FirstPhysicalPar();
1873 npar = par->Next()->NextAfterFootnote();
1876 && (npar->depth > par->depth))
1877 npar = npar->Next()->NextAfterFootnote();
1879 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1881 p1 = ppar->pextra_width,
1882 p2 = ppar->pextra_widthp;
1883 ppar->SetPExtraType(bparams, ppar->pextra_type,
1884 p1.c_str(), p2.c_str());
1886 if ((par->pextra_type == PEXTRA_NONE) &&
1887 npar && (npar->pextra_type != PEXTRA_NONE)) {
1889 p1 = npar->pextra_width,
1890 p2 = npar->pextra_widthp;
1891 npar->SetPExtraType(bparams, npar->pextra_type,
1892 p1.c_str(), p2.c_str());
1898 // if the layout of a paragraph contains a manual label, the beginning of the
1899 // main body is the beginning of the second word. This is what the par-
1900 // function returns. If the layout does not contain a label, the main
1901 // body always starts with position 0. This differentiation is necessary,
1902 // because there cannot be a newline or a blank <= the beginning of the
1903 // main body in TeX.
1905 int LyXParagraph::BeginningOfMainBody() const
1907 if (FirstPhysicalPar() != this)
1910 // Unroll the first two cycles of the loop
1911 // and remember the previous character to
1912 // remove unnecessary GetChar() calls
1915 && GetChar(i) != LyXParagraph::META_NEWLINE
1918 char previous_char = 0, temp = 0;
1920 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1921 // Yes, this ^ is supposed to be "= " not "=="
1924 && previous_char != ' '
1925 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1927 previous_char = temp;
1932 if (i == 0 && i == size() &&
1933 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1934 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1935 ++i; /* the cursor should not jump
1936 * to the main body if there
1942 LyXParagraph * LyXParagraph::DepthHook(int deth)
1944 LyXParagraph * newpar = this;
1949 newpar = newpar->FirstPhysicalPar()->Previous();
1950 } while (newpar && newpar->GetDepth() > deth
1951 && newpar->footnoteflag == footnoteflag);
1954 if (Previous() || GetDepth())
1955 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1959 return newpar->FirstPhysicalPar();
1963 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1965 LyXParagraph const * newpar = this;
1970 newpar = newpar->FirstPhysicalPar()->Previous();
1971 } while (newpar && newpar->GetDepth() > deth
1972 && newpar->footnoteflag == footnoteflag);
1975 if (Previous() || GetDepth())
1976 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1980 return newpar->FirstPhysicalPar();
1984 int LyXParagraph::AutoDeleteInsets()
1987 InsetList::size_type index = 0;
1988 while (index < insetlist.size()) {
1989 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1990 Erase(insetlist[index].pos);
1991 // Erase() calls to insetlist.erase(&insetlist[index])
1992 // so index shouldn't be increased.
2001 LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2003 InsetList::iterator it = lower_bound(insetlist.begin(),
2006 return inset_iterator(it);
2010 // returns -1 if inset not found
2011 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2014 // We could use lower_bound here too, we just need to add
2015 // the approp. operator() to matchIT (and change the name
2016 // of that struct). Code would then be:
2017 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2019 // inset, matchIT());
2020 // if ((*cit).inset == inset) {
2021 // return (*cit).pos;
2023 for (InsetList::const_iterator cit = insetlist.begin();
2024 cit != insetlist.end(); ++cit) {
2025 if ((*cit).inset == inset) {
2029 // Think about footnotes.
2030 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2031 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2033 NextAfterFootnote()->GetPositionOfInset(inset);
2035 return text.size() + 1 + further;
2041 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2042 BufferParams const & bparams,
2043 ostream & os, TexRow & texrow,
2046 TexRow & foot_texrow,
2049 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2050 LyXLayout const & style =
2051 textclasslist.Style(bparams.textclass,
2054 bool further_blank_line = false;
2056 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2058 if (start_of_appendix) {
2059 os << "\\appendix\n";
2063 if (!spacing.isDefault()
2064 && (!Previous() || !Previous()->HasSameLayout(this))) {
2065 os << spacing.writeEnvirBegin() << "\n";
2069 if (tex_code_break_column && style.isCommand()){
2074 if (pagebreak_top) {
2076 further_blank_line = true;
2078 if (added_space_top.kind() != VSpace::NONE) {
2079 os << added_space_top.asLatexCommand(bparams);
2080 further_blank_line = true;
2084 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2085 << "\\vspace{-1\\parskip}";
2086 further_blank_line = true;
2089 if (further_blank_line){
2094 Language const * language = getParLanguage(bparams);
2095 Language const * doc_language = bparams.language_info;
2096 Language const * previous_language = previous
2097 ? previous->getParLanguage(bparams) : doc_language;
2098 if (language != doc_language && language != previous_language) {
2099 os << subst(lyxrc.language_command_begin, "$$lang",
2105 if (bparams.inputenc == "auto" &&
2106 language->encoding() != previous_language->encoding()) {
2107 os << "\\inputencoding{"
2108 << language->encoding()->LatexName()
2113 switch (style.latextype) {
2116 << style.latexname()
2117 << style.latexparam();
2119 case LATEX_ITEM_ENVIRONMENT:
2121 bibkey->Latex(buf, os, false, false);
2125 case LATEX_LIST_ENVIRONMENT:
2132 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2135 // Spit out footnotes
2136 LyXParagraph * par = next;
2137 if (lyxrc.rtl_support) {
2138 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2139 && next->footnoteflag != footnoteflag) {
2140 LyXParagraph * p = 0;
2141 bool is_rtl = (size() > 0)
2142 ? GetFontSettings(bparams,
2143 size()-1).isRightToLeft()
2144 : language->RightToLeft();
2145 if ( (p = NextAfterFootnote()) != 0 &&
2147 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2148 is_rtl = getParLanguage(bparams)->RightToLeft();
2149 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2150 && par->footnoteflag != footnoteflag) {
2151 par = par->TeXFootnote(buf, bparams,
2153 foot_texrow, foot_count,
2155 par->SimpleTeXOnePar(buf, bparams,
2156 os, texrow, moving_arg);
2157 is_rtl = (par->size() > 0)
2158 ? par->GetFontSettings(bparams,
2159 par->size()-1).isRightToLeft()
2160 : language->RightToLeft();
2162 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2163 (p = par->NextAfterFootnote()) != 0 &&
2165 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2166 is_rtl = language->RightToLeft();
2171 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2172 && par->footnoteflag != footnoteflag) {
2173 par = par->TeXFootnote(buf, bparams,
2175 foot, foot_texrow, foot_count,
2177 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2183 // Make sure that \\par is done with the font of the last
2184 // character if this has another size as the default.
2185 // This is necessary because LaTeX (and LyX on the screen)
2186 // calculates the space between the baselines according
2187 // to this font. (Matthias)
2188 LyXFont font = getFont(bparams, Last() - 1);
2190 if (style.resfont.size() != font.size()) {
2196 } else if (textclasslist.Style(bparams.textclass,
2197 GetLayout()).isCommand()) {
2198 if (style.resfont.size() != font.size()) {
2204 } else if (style.resfont.size() != font.size()){
2205 os << "{\\" << font.latexSize() << " \\par}";
2208 if (language != doc_language &&
2210 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2211 || par->getParLanguage(bparams) != language)) {
2213 << subst(lyxrc.language_command_end, "$$lang",
2214 doc_language->lang());
2217 switch (style.latextype) {
2218 case LATEX_ITEM_ENVIRONMENT:
2219 case LATEX_LIST_ENVIRONMENT:
2220 if (par && (depth < par->depth)) {
2225 case LATEX_ENVIRONMENT:
2226 // if its the last paragraph of the current environment
2227 // skip it otherwise fall through
2229 && (par->layout != layout
2230 || par->depth != depth
2231 || par->pextra_type != pextra_type))
2234 // we don't need it for the last paragraph!!!
2235 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2236 && footnotekind != LyXParagraph::FOOTNOTE
2237 && footnotekind != LyXParagraph::MARGIN
2241 // don't insert this if we would be adding it
2242 // before or after a table in a float. This
2243 // little trick is needed in order to allow
2244 // use of tables in \subfigures or \subtables.
2250 further_blank_line = false;
2252 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2253 further_blank_line = true;
2256 if (added_space_bottom.kind() != VSpace::NONE) {
2257 os << added_space_bottom.asLatexCommand(bparams);
2258 further_blank_line = true;
2261 if (pagebreak_bottom) {
2263 further_blank_line = true;
2266 if (further_blank_line){
2271 if (!spacing.isDefault()
2272 && (!par || !par->HasSameLayout(this))) {
2273 os << spacing.writeEnvirEnd() << "\n";
2277 // we don't need it for the last paragraph!!!
2278 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2279 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2284 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2289 // This one spits out the text of the paragraph
2290 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2291 BufferParams const & bparams,
2292 ostream & os, TexRow & texrow,
2295 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2299 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2302 bool return_value = false;
2304 LyXLayout const & style =
2305 textclasslist.Style(bparams.textclass,
2307 LyXFont basefont, last_font;
2309 // Maybe we have to create a optional argument.
2310 size_type main_body;
2311 if (style.labeltype != LABEL_MANUAL)
2314 main_body = BeginningOfMainBody();
2316 if (main_body > 0) {
2318 basefont = getFont(bparams, -2); // Get label font
2320 basefont = getFont(bparams, -1); // Get layout font
2328 if (style.isCommand()) {
2331 } else if (align != LYX_ALIGN_LAYOUT) {
2334 return_value = true;
2338 moving_arg |= style.needprotect;
2340 // Which font is currently active?
2341 LyXFont running_font(basefont);
2342 // Do we have an open font change?
2343 bool open_font = false;
2345 texrow.start(this, 0);
2347 for (size_type i = 0; i < size(); ++i) {
2349 // First char in paragraph or after label?
2350 if (i == main_body && !IsDummy()) {
2351 if (main_body > 0) {
2353 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2356 basefont = getFont(bparams, -1); // Now use the layout font
2357 running_font = basefont;
2361 if (style.isCommand()) {
2364 } else if (align != LYX_ALIGN_LAYOUT) {
2367 return_value = true;
2371 os << "\\noindent ";
2375 case LYX_ALIGN_NONE:
2376 case LYX_ALIGN_BLOCK:
2377 case LYX_ALIGN_LAYOUT:
2378 case LYX_ALIGN_SPECIAL:
2380 case LYX_ALIGN_LEFT:
2381 if (getParLanguage(bparams)->lang() != "hebrew") {
2382 os << "\\raggedright ";
2385 os << "\\raggedleft ";
2389 case LYX_ALIGN_RIGHT:
2390 if (getParLanguage(bparams)->lang() != "hebrew") {
2391 os << "\\raggedleft ";
2394 os << "\\raggedright ";
2398 case LYX_ALIGN_CENTER:
2399 os << "\\centering ";
2407 // Fully instantiated font
2408 LyXFont font = getFont(bparams, i);
2409 LyXParagraph * p = 0;
2410 if (i == 0 && previous &&
2411 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2412 (p = PreviousBeforeFootnote()) != 0)
2413 last_font = p->getFont(bparams, p->size()-1);
2415 last_font = running_font;
2417 // Spaces at end of font change are simulated to be
2418 // outside font change, i.e. we write "\textXX{text} "
2419 // rather than "\textXX{text }". (Asger)
2420 if (open_font && c == ' ' && i <= size() - 2
2421 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2422 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2423 font = getFont(bparams, i + 1);
2425 // We end font definition before blanks
2426 if (!font.equalExceptLatex(running_font) && open_font) {
2427 column += running_font.latexWriteEndChanges(os,
2429 (i == main_body-1) ? basefont : font);
2430 running_font = basefont;
2434 // Blanks are printed before start of fontswitch
2436 // Do not print the separation of the optional argument
2437 if (i != main_body - 1) {
2438 SimpleTeXBlanks(os, texrow, i,
2439 column, font, style);
2443 // Do we need to change font?
2444 if (!font.equalExceptLatex(running_font)
2445 && i != main_body-1) {
2446 column += font.latexWriteStartChanges(os, basefont,
2448 running_font = font;
2452 if (c == LyXParagraph::META_NEWLINE) {
2453 // newlines are handled differently here than
2454 // the default in SimpleTeXSpecialChars().
2455 if (!style.newline_allowed
2456 || font.latex() == LyXFont::ON) {
2460 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2463 basefont = getFont(bparams, -1);
2464 running_font = basefont;
2465 if (font.family() ==
2466 LyXFont::TYPEWRITER_FAMILY) {
2474 texrow.start(this, i + 1);
2477 SimpleTeXSpecialChars(buf, bparams,
2478 os, texrow, moving_arg,
2479 font, running_font, basefont,
2480 open_font, style, i, column, c);
2484 // If we have an open font definition, we have to close it
2486 LyXParagraph * p = 0;
2487 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2488 && (p = NextAfterFootnote()) != 0)
2489 running_font.latexWriteEndChanges(os, basefont,
2490 p->getFont(bparams, 0));
2492 running_font.latexWriteEndChanges(os, basefont, basefont);
2495 // Needed if there is an optional argument but no contents.
2496 if (main_body > 0 && main_body == size()) {
2498 return_value = false;
2501 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2502 return return_value;
2506 // This one spits out the text of a table paragraph
2507 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2508 BufferParams const & bparams,
2509 ostream & os, TexRow & texrow)
2511 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2513 bool return_value = false;
2515 LyXLayout const & style =
2516 textclasslist.Style(bparams.textclass, GetLayout());
2519 if (!IsDummy()) { // it is dummy if it is in a float!!!
2520 if (style.isCommand()) {
2523 } else if (align != LYX_ALIGN_LAYOUT) {
2526 return_value = true;
2529 os << "\\noindent ";
2533 case LYX_ALIGN_NONE:
2534 case LYX_ALIGN_BLOCK:
2535 case LYX_ALIGN_LAYOUT:
2536 case LYX_ALIGN_SPECIAL: break;
2537 case LYX_ALIGN_LEFT:
2538 os << "\\raggedright ";
2541 case LYX_ALIGN_RIGHT:
2542 os << "\\raggedleft ";
2545 case LYX_ALIGN_CENTER:
2546 os << "\\centering ";
2552 LyXFont basefont = getFont(bparams, -1); // Get layout font
2553 // Which font is currently active?
2554 LyXFont running_font = basefont;
2556 // Do we have an open font change?
2557 bool open_font = false;
2558 int current_cell_number = -1;
2559 int tmp = table->TexEndOfCell(os, current_cell_number);
2560 for (; tmp > 0 ; --tmp)
2563 texrow.start(this, 0);
2565 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2566 bool first_in_cell = true;
2568 for (size_type i = 0; i < size(); ++i) {
2569 char c = GetChar(i);
2570 if (table->IsContRow(current_cell_number + 1)) {
2571 if (c == LyXParagraph::META_NEWLINE)
2572 ++current_cell_number;
2577 if (first_in_cell && is_rtl) {
2580 first_in_cell = false;
2583 // Fully instantiated font
2584 LyXFont font = getFont(bparams, i);
2585 last_font = running_font;
2587 // Spaces at end of font change are simulated to be
2588 // outside font change.
2589 // i.e. we write "\textXX{text} " rather than
2590 // "\textXX{text }". (Asger)
2591 if (open_font && c == ' ' && i <= size() - 2
2592 && getFont(bparams, i + 1) != running_font
2593 && getFont(bparams, i + 1) != font) {
2594 font = getFont(bparams, i + 1);
2597 // We end font definition before blanks
2598 if (font != running_font && open_font) {
2599 column += running_font.latexWriteEndChanges(os,
2602 running_font = basefont;
2605 // Blanks are printed before start of fontswitch
2607 SimpleTeXBlanks(os, texrow, i, column, font, style);
2609 // Do we need to change font?
2610 if (font != running_font) {
2611 column += font.latexWriteStartChanges(os, basefont,
2613 running_font = font;
2616 // Do we need to turn on LaTeX mode?
2617 if (font.latex() != running_font.latex()) {
2618 if (font.latex() == LyXFont::ON
2619 && style.needprotect) {
2624 if (c == LyXParagraph::META_NEWLINE) {
2625 // special case for inside a table
2626 // different from default case in
2627 // SimpleTeXSpecialChars()
2629 column += running_font
2630 .latexWriteEndChanges(os, basefont,
2634 basefont = getFont(bparams, -1);
2635 running_font = basefont;
2636 ++current_cell_number;
2637 if (table->CellHasContRow(current_cell_number) >= 0) {
2638 TeXContTableRows(buf, bparams, os, i + 1,
2639 current_cell_number,
2642 if (is_rtl && !first_in_cell) {
2644 first_in_cell = true;
2647 // if this cell follow only ContRows till end don't
2648 // put the EndOfCell because it is put after the
2650 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2651 --current_cell_number;
2654 int tmp = table->TexEndOfCell(os,
2655 current_cell_number);
2658 } else if (tmp < 0) {
2664 texrow.start(this, i + 1);
2666 SimpleTeXSpecialChars(buf, bparams,
2668 font, running_font, basefont,
2669 open_font, style, i, column, c);
2673 // If we have an open font definition, we have to close it
2675 running_font.latexWriteEndChanges(os, basefont, basefont);
2677 ++current_cell_number;
2678 if (is_rtl && !first_in_cell)
2680 tmp = table->TexEndOfCell(os, current_cell_number);
2681 for (; tmp > 0; --tmp)
2683 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2684 return return_value;
2688 // This one spits out the text off ContRows in tables
2689 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2690 BufferParams const & bparams,
2692 LyXParagraph::size_type i,
2693 int current_cell_number,
2694 int & column, TexRow & texrow)
2696 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2700 bool return_value = false;
2701 LyXLayout const & style =
2702 textclasslist.Style(bparams.textclass,
2704 LyXFont basefont = getFont(bparams, -1); // Get layout font
2706 // Which font is currently active?
2707 LyXFont running_font = basefont;
2708 // Do we have an open font change?
2709 bool open_font = false;
2711 size_type lastpos = i;
2712 int cell = table->CellHasContRow(current_cell_number);
2713 ++current_cell_number;
2716 // first find the right position
2718 for (; (i < size()) && (current_cell_number<cell); ++i) {
2720 if (c == LyXParagraph::META_NEWLINE)
2721 ++current_cell_number;
2725 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2729 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2734 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2738 // Fully instantiated font
2739 LyXFont font = getFont(bparams, i);
2740 last_font = running_font;
2742 // Spaces at end of font change are simulated to
2743 // be outside font change. i.e. we write
2744 // "\textXX{text} " rather than "\textXX{text }".
2746 if (open_font && c == ' ' && i <= size() - 2
2747 && getFont(bparams, i + 1) != running_font
2748 && getFont(bparams, i + 1) != font) {
2749 font = getFont(bparams, i + 1);
2752 // We end font definition before blanks
2753 if (font != running_font && open_font) {
2754 column += running_font.latexWriteEndChanges(os, basefont, font);
2755 running_font = basefont;
2758 // Blanks are printed before start of fontswitch
2760 SimpleTeXBlanks(os, texrow, i,
2761 column, font, style);
2763 // Do we need to change font?
2764 if (font != running_font) {
2766 font.latexWriteStartChanges(os,
2769 running_font = font;
2772 // Do we need to turn on LaTeX mode?
2773 if (font.latex() != running_font.latex()) {
2774 if (font.latex() == LyXFont::ON
2775 && style.needprotect) {
2780 SimpleTeXSpecialChars(buf, bparams,
2781 os, texrow, false, font,
2782 running_font, basefont,
2783 open_font, style, i, column, c);
2785 // If we have an open font definition, we have to close it
2787 running_font.latexWriteEndChanges(os, basefont,
2791 basefont = getFont(bparams, -1);
2792 running_font = basefont;
2793 cell = table->CellHasContRow(current_cell_number);
2795 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2796 return return_value;
2800 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2802 bool retval = false;
2804 case LyXParagraph::META_HFILL:
2805 sgml_string.erase();
2807 case LyXParagraph::META_NEWLINE:
2811 sgml_string = "&";
2814 sgml_string = "<";
2817 sgml_string = ">";
2820 sgml_string = "$";
2823 sgml_string = "#";
2826 sgml_string = "%";
2829 sgml_string = "[";
2832 sgml_string = "]";
2835 sgml_string = "{";
2838 sgml_string = "}";
2841 sgml_string = "˜";
2844 sgml_string = """;
2847 sgml_string = "\";
2853 case '\0': // Ignore :-)
2854 sgml_string.erase();
2864 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
2865 ostream & os, string & extra,
2866 int & desc_on, int depth)
2868 BufferParams const & bparams = buffer->params;
2870 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2872 LyXFont font1, font2;
2875 size_type main_body;
2876 bool emph_flag = false;
2878 LyXLayout const & style =
2879 textclasslist.Style(bparams.textclass,
2882 if (style.labeltype != LABEL_MANUAL)
2885 main_body = BeginningOfMainBody();
2887 // Gets paragraph main font.
2889 font1 = style.labelfont;
2893 int char_line_count = depth;
2894 os << newlineAndDepth(depth);
2895 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2896 os << "<INFORMALTABLE>"
2897 << newlineAndDepth(++depth);
2899 int current_cell_number = -1;
2900 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2902 // Parsing main loop.
2903 for (size_type i = 0; i < size(); ++i) {
2905 if (table->IsContRow(current_cell_number+1)) {
2906 if (c == LyXParagraph::META_NEWLINE)
2907 ++current_cell_number;
2912 // Fully instantiated font
2913 font2 = getFont(bparams, i);
2915 // Handle <emphasis> tag.
2916 if (font1.emph() != font2.emph() && i) {
2917 if (font2.emph() == LyXFont::ON) {
2920 } else if (emph_flag) {
2921 os << "</emphasis>";
2925 if (c == LyXParagraph::META_NEWLINE) {
2926 // We have only to control for emphasis open here!
2928 os << "</emphasis>";
2931 font1 = font2 = getFont(bparams, -1);
2932 ++current_cell_number;
2933 if (table->CellHasContRow(current_cell_number) >= 0) {
2934 DocBookContTableRows(buffer,
2935 os, extra, desc_on, i + 1,
2936 current_cell_number,
2939 // if this cell follow only ContRows till end don't
2940 // put the EndOfCell because it is put after the
2942 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2943 --current_cell_number;
2946 tmp = table->DocBookEndOfCell(os,
2947 current_cell_number,
2952 } else if (c == LyXParagraph::META_INSET) {
2953 inset = GetInset(i);
2955 std::ostringstream ost;
2956 inset->DocBook(buffer, ost);
2957 string tmp_out = ost.str().c_str();
2960 inset->DocBook(buffer, ost);
2962 char * ctmp = ost.str();
2963 string tmp_out(ctmp);
2967 // This code needs some explanation:
2968 // Two insets are treated specially
2969 // label if it is the first element in a
2970 // command paragraph
2972 // graphics inside tables or figure floats
2974 // title (the equivalente in latex for this
2976 // and title should come first
2979 if(desc_on != 3 || i != 0) {
2980 if(tmp_out[0] == '@') {
2982 extra += frontStrip(tmp_out,
2985 os << frontStrip(tmp_out,
2990 } else if (font2.latex() == LyXFont::ON) {
2991 // "TeX"-Mode on == > SGML-Mode on.
2997 if (linuxDocConvertChar(c, sgml_string)
2998 && !style.free_spacing) {
2999 // in freespacing mode, spaces are
3000 // non-breaking characters
3005 << "</term><listitem><para>";
3017 // Needed if there is an optional argument but no contents.
3018 if (main_body > 0 && main_body == size()) {
3023 os << "</emphasis>";
3026 ++current_cell_number;
3027 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3028 // Resets description flag correctly.
3031 // <term> not closed...
3035 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3036 os << "</INFORMALTABLE>";
3038 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3043 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3044 ostream & os, string & extra,
3046 LyXParagraph::size_type i,
3047 int current_cell_number, int &column)
3052 BufferParams const & bparams = buffer->params;
3054 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3059 //string emph = "emphasis";
3060 bool emph_flag = false;
3061 int char_line_count = 0;
3063 LyXLayout const & style =
3064 textclasslist.Style(bparams.textclass,
3067 size_type main_body;
3068 if (style.labeltype != LABEL_MANUAL)
3071 main_body = BeginningOfMainBody();
3073 // Gets paragraph main font.
3076 font1 = style.labelfont;
3080 size_type lastpos = i;
3081 int cell = table->CellHasContRow(current_cell_number);
3082 ++current_cell_number;
3084 // first find the right position
3086 for (; i < size() && current_cell_number < cell; ++i) {
3088 if (c == LyXParagraph::META_NEWLINE)
3089 ++current_cell_number;
3093 // I don't know how to handle this so I comment it
3094 // for the moment (Jug)
3095 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3096 // file += " \\\\\n";
3099 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3104 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3108 // Fully instantiated font
3109 font2 = getFont(bparams, i);
3111 // Handle <emphasis> tag.
3112 if (font1.emph() != font2.emph() && i) {
3113 if (font2.emph() == LyXFont::ON) {
3116 } else if (emph_flag) {
3117 os << "</emphasis>";
3121 if (c == LyXParagraph::META_INSET) {
3122 inset = GetInset(i);
3124 std::ostringstream ost;
3125 inset->DocBook(buffer, ost);
3126 string tmp_out = ost.str().c_str();
3129 inset->DocBook(buffer, ost);
3131 char * ctmp = ost.str();
3132 string tmp_out(ctmp);
3136 // This code needs some explanation:
3137 // Two insets are treated specially
3138 // label if it is the first element in a
3139 // command paragraph
3141 // graphics inside tables or figure floats
3142 // can't go on title (the equivalente in
3143 // latex for this case is caption and title
3144 // should come first
3147 if(desc_on != 3 || i != 0) {
3148 if(tmp_out[0] == '@') {
3150 extra += frontStrip(tmp_out, '@');
3152 os << frontStrip(tmp_out, '@');
3156 } else if (font2.latex() == LyXFont::ON) {
3157 // "TeX"-Mode on == > SGML-Mode on.
3163 if (linuxDocConvertChar(c, sgml_string)
3164 && !style.free_spacing) {
3165 // in freespacing mode, spaces are
3166 // non-breaking characters
3171 << "</term><listitem><para>";
3181 // we have only to control for emphasis open here!
3183 os << "</emphasis>";
3186 font1 = font2 = getFont(bparams, -1);
3187 cell = table->CellHasContRow(current_cell_number);
3189 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3193 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3194 LyXParagraph::size_type const i,
3195 int & column, LyXFont const & font,
3196 LyXLayout const & style)
3198 if (column > tex_code_break_column
3200 && GetChar(i - 1) != ' '
3202 // In LaTeX mode, we don't want to
3203 // break lines since some commands
3205 && ! (font.latex() == LyXFont::ON)
3206 // same in FreeSpacing mode
3207 && !style.free_spacing
3208 // In typewriter mode, we want to avoid
3209 // ! . ? : at the end of a line
3210 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3211 && (GetChar(i-1) == '.'
3212 || GetChar(i-1) == '?'
3213 || GetChar(i-1) == ':'
3214 || GetChar(i-1) == '!'))) {
3215 if (tex_code_break_column == 0) {
3216 // in batchmode we need LaTeX to still
3217 // see it as a space not as an extra '\n'
3223 texrow.start(this, i + 1);
3225 } else if (font.latex() == LyXFont::OFF) {
3226 if (style.free_spacing) {
3235 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3236 BufferParams const & bparams,
3237 ostream & os, TexRow & texrow,
3240 LyXFont & running_font,
3243 LyXLayout const & style,
3244 LyXParagraph::size_type & i,
3245 int & column, char const c)
3247 // Two major modes: LaTeX or plain
3248 // Handle here those cases common to both modes
3249 // and then split to handle the two modes separately.
3251 case LyXParagraph::META_INSET: {
3252 Inset * inset = GetInset(i);
3255 int len = os.tellp();
3256 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3257 || inset->LyxCode() == Inset::MATH_CODE
3258 || inset->LyxCode() == Inset::URL_CODE)
3259 && running_font.isRightToLeft()) {
3264 int tmp = inset->Latex(buf, os, moving_arg,
3265 style.free_spacing);
3273 column += os.tellp() - len;
3282 case LyXParagraph::META_NEWLINE:
3284 column += running_font.latexWriteEndChanges(os,
3289 basefont = getFont(bparams, -1);
3290 running_font = basefont;
3293 case LyXParagraph::META_HFILL:
3299 // And now for the special cases within each mode
3300 // Are we in LaTeX mode?
3301 if (font.latex() == LyXFont::ON) {
3302 // at present we only have one option
3303 // but I'll leave it as a switch statement
3304 // so its simpler to extend. (ARRae)
3307 // make sure that we will not print
3308 // error generating chars to the tex
3309 // file. This test would not be needed
3310 // if it were done in the buffer
3318 // Plain mode (i.e. not LaTeX)
3321 os << "\\textbackslash{}";
3325 case '°': case '±': case '²': case '³':
3326 case '×': case '÷': case '¹': case 'ª':
3327 case 'º': case '¬': case 'µ':
3328 if (bparams.inputenc == "latin1" ||
3329 (bparams.inputenc == "auto" &&
3330 font.language()->encoding()->LatexName()
3332 os << "\\ensuremath{"
3341 case '|': case '<': case '>':
3342 // In T1 encoding, these characters exist
3343 if (lyxrc.fontenc == "T1") {
3345 //... but we should avoid ligatures
3346 if ((c == '>' || c == '<')
3348 && GetChar(i + 1) == c) {
3349 //os << "\\textcompwordmark{}";
3350 // Jean-Marc, have a look at
3351 // this. IÂ think this works
3359 // Typewriter font also has them
3360 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3364 // Otherwise, we use what LaTeX
3368 os << "\\textless{}";
3372 os << "\\textgreater{}";
3376 os << "\\textbar{}";
3382 case '-': // "--" in Typewriter mode -> "-{}-"
3384 && GetChar(i + 1) == '-'
3385 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3394 os << "\\char`\\\"{}";
3399 if (bparams.inputenc == "default") {
3408 case '%': case '#': case '{':
3415 os << "\\textasciitilde{}";
3420 os << "\\textasciicircum{}";
3424 case '*': case '[': case ']':
3425 // avoid being mistaken for optional arguments
3426 os << '{' << c << '}';
3431 // Blanks are printed before font switching.
3432 // Sure? I am not! (try nice-latex)
3433 // I am sure it's correct. LyX might be smarter
3434 // in the future, but for now, nothing wrong is
3439 /* idea for labels --- begin*/
3443 && font.family() != LyXFont::TYPEWRITER_FAMILY
3444 && GetChar(i + 1) == 'y'
3445 && GetChar(i + 2) == 'X') {
3453 && font.family() != LyXFont::TYPEWRITER_FAMILY
3454 && GetChar(i + 1) == 'e'
3455 && GetChar(i + 2) == 'X') {
3460 // Check for "LaTeX2e"
3463 && font.family() != LyXFont::TYPEWRITER_FAMILY
3464 && GetChar(i + 1) == 'a'
3465 && GetChar(i + 2) == 'T'
3466 && GetChar(i + 3) == 'e'
3467 && GetChar(i + 4) == 'X'
3468 && GetChar(i + 5) == '2'
3469 && GetChar(i + 6) == 'e') {
3474 // Check for "LaTeX"
3477 && font.family() != LyXFont::TYPEWRITER_FAMILY
3478 && GetChar(i + 1) == 'a'
3479 && GetChar(i + 2) == 'T'
3480 && GetChar(i + 3) == 'e'
3481 && GetChar(i + 4) == 'X') {
3485 /* idea for labels --- end*/
3486 } else if (c != '\0') {
3496 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3497 BufferParams const & bparams,
3498 ostream & os, TexRow & texrow,
3500 TexRow & foot_texrow,
3503 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3504 LyXParagraph * par = this;
3507 (par->depth == depth) &&
3508 (par->footnoteflag == footnoteflag)) {
3510 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3511 if (textclasslist.Style(bparams.textclass,
3512 par->layout).isEnvironment()
3513 || par->pextra_type != PEXTRA_NONE) {
3514 par = par->TeXEnvironment(buf, bparams,
3519 par = par->TeXOnePar(buf, bparams,
3525 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3531 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3532 BufferParams const & bparams,
3533 ostream & os, TexRow & texrow,
3535 TexRow & foot_texrow,
3538 bool eindent_open = false;
3539 bool foot_this_level = false;
3540 // flags when footnotetext should be appended to file.
3541 static bool minipage_open = false;
3542 static int minipage_open_depth = 0;
3543 char par_sep = bparams.paragraph_separation;
3545 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3547 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3549 LyXLayout const & style =
3550 textclasslist.Style(bparams.textclass,
3553 if (pextra_type == PEXTRA_INDENT) {
3554 if (!pextra_width.empty()) {
3555 os << "\\begin{LyXParagraphIndent}{"
3556 << pextra_width << "}\n";
3558 //float ib = atof(pextra_widthp.c_str())/100;
3559 // string can't handle floats at present (971109)
3560 // so I'll do a conversion by hand knowing that
3561 // the limits are 0.0 to 1.0. ARRae.
3562 os << "\\begin{LyXParagraphIndent}{";
3563 switch (pextra_widthp.length()) {
3575 os << "\\columnwidth}\n";
3578 eindent_open = true;
3580 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3581 if (pextra_hfill && Previous() &&
3582 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3583 os << "\\hfill{}\n";
3586 if (par_sep == BufferParams::PARSEP_INDENT) {
3587 os << "{\\setlength\\parindent{0pt}\n";
3590 os << "\\begin{minipage}";
3591 switch(pextra_alignment) {
3592 case MINIPAGE_ALIGN_TOP:
3595 case MINIPAGE_ALIGN_MIDDLE:
3598 case MINIPAGE_ALIGN_BOTTOM:
3602 if (!pextra_width.empty()) {
3603 os << '{' << pextra_width << "}\n";
3605 //float ib = atof(par->pextra_width.c_str())/100;
3606 // string can't handle floats at present
3607 // so I'll do a conversion by hand knowing that
3608 // the limits are 0.0 to 1.0. ARRae.
3610 switch (pextra_widthp.length()) {
3622 os << "\\columnwidth}\n";
3625 if (par_sep == BufferParams::PARSEP_INDENT) {
3626 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3629 minipage_open = true;
3630 minipage_open_depth = depth;
3633 #ifdef WITH_WARNINGS
3634 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3635 //I disabled it because it breaks when lists span on several
3638 if (style.isEnvironment()){
3639 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3640 #ifdef FANCY_FOOTNOTE_CODE
3641 if (foot_count < 0) {
3642 // flag that footnote[mark][text] should be
3643 // used for any footnotes from now on
3645 foot_this_level = true;
3648 os << "\\begin{" << style.latexname() << "}{"
3649 << labelwidthstring << "}\n";
3650 } else if (style.labeltype == LABEL_BIBLIO) {
3652 os << "\\begin{" << style.latexname() << "}{"
3653 << bibitemWidest(current_view)
3655 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3656 #ifdef FANCY_FOOTNOTE_CODE
3657 if (foot_count < 0) {
3658 // flag that footnote[mark][text] should be
3659 // used for any footnotes from now on
3661 foot_this_level = true;
3664 os << "\\begin{" << style.latexname() << '}'
3665 << style.latexparam() << '\n';
3667 os << "\\begin{" << style.latexname() << '}'
3668 << style.latexparam() << '\n';
3671 LyXParagraph * par = this;
3673 par = par->TeXOnePar(buf, bparams,
3675 foot, foot_texrow, foot_count);
3677 if (minipage_open && par && !style.isEnvironment() &&
3678 (par->pextra_type == PEXTRA_MINIPAGE) &&
3679 par->pextra_start_minipage) {
3680 os << "\\end{minipage}\n";
3682 if (par_sep == BufferParams::PARSEP_INDENT) {
3686 minipage_open = false;
3688 if (par && par->depth > depth) {
3689 if (textclasslist.Style(bparams.textclass,
3690 par->layout).isParagraph()
3693 // How to handle this? (Lgb)
3694 //&& !suffixIs(os, "\n\n")
3696 // There should be at least one '\n' already
3697 // but we need there to be two for Standard
3698 // paragraphs that are depth-increment'ed to be
3699 // output correctly. However, tables can
3700 // also be paragraphs so don't adjust them.
3703 // Will it ever harm to have one '\n' too
3704 // many? i.e. that we sometimes will have
3705 // three in a row. (Lgb)
3709 par = par->TeXDeeper(buf, bparams, os, texrow,
3710 foot, foot_texrow, foot_count);
3712 if (par && par->layout == layout && par->depth == depth &&
3713 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3714 if (par->pextra_hfill && par->Previous() &&
3715 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3716 os << "\\hfill{}\n";
3719 if (par_sep == BufferParams::PARSEP_INDENT) {
3720 os << "{\\setlength\\parindent{0pt}\n";
3723 os << "\\begin{minipage}";
3724 switch(par->pextra_alignment) {
3725 case MINIPAGE_ALIGN_TOP:
3728 case MINIPAGE_ALIGN_MIDDLE:
3731 case MINIPAGE_ALIGN_BOTTOM:
3735 if (!par->pextra_width.empty()) {
3736 os << '{' << par->pextra_width << "}\n";
3738 //float ib = atof(par->pextra_widthp.c_str())/100;
3739 // string can't handle floats at present
3740 // so I'll do a conversion by hand knowing that
3741 // the limits are 0.0 to 1.0. ARRae.
3743 switch (par->pextra_widthp.length()) {
3748 os << "0." << par->pextra_widthp;
3751 os << "0.0" << par->pextra_widthp;
3753 os << "\\columnwidth}\n";
3756 if (par_sep == BufferParams::PARSEP_INDENT) {
3757 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3760 minipage_open = true;
3761 minipage_open_depth = par->depth;
3764 && par->layout == layout
3765 && par->depth == depth
3766 && par->pextra_type == pextra_type
3767 && par->footnoteflag == footnoteflag);
3769 if (style.isEnvironment()) {
3770 os << "\\end{" << style.latexname() << '}';
3771 // maybe this should go after the minipage closes?
3772 if (foot_this_level) {
3773 if (foot_count >= 1) {
3774 if (foot_count > 1) {
3775 os << "\\addtocounter{footnote}{-"
3780 texrow += foot_texrow;
3782 foot_texrow.reset();
3787 if (minipage_open && (minipage_open_depth == depth) &&
3788 (!par || par->pextra_start_minipage ||
3789 par->pextra_type != PEXTRA_MINIPAGE)) {
3790 os << "\\end{minipage}\n";
3792 if (par_sep == BufferParams::PARSEP_INDENT) {
3796 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3797 os << "\\medskip\n\n";
3801 minipage_open = false;
3804 os << "\\end{LyXParagraphIndent}\n";
3807 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3808 && par->pextra_hfill)) {
3812 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3813 return par; // ale970302
3818 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3819 BufferParams const & bparams,
3820 ostream & os, TexRow & texrow,
3821 ostream & foot, TexRow & foot_texrow,
3825 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3826 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3827 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3828 "No footnote!" << endl;
3830 LyXParagraph * par = this;
3831 LyXLayout const & style =
3832 textclasslist.Style(bparams.textclass,
3833 previous->GetLayout());
3835 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3836 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3837 "Float other than footnote in command"
3838 " with moving argument is illegal" << endl;
3841 if (footnotekind != LyXParagraph::FOOTNOTE
3842 && footnotekind != LyXParagraph::MARGIN
3845 // How to solve this?
3846 //&& !suffixIs(file, '\n')
3848 // we need to ensure that real floats like tables and figures
3849 // have their \begin{} on a new line otherwise we can get
3850 // incorrect results when using the endfloat.sty package
3851 // especially if two floats follow one another. ARRae 981022
3852 // NOTE: if the file is length 0 it must have just been
3853 // written out so we assume it ended with a '\n'
3855 // As far as I can see there is never any harm in writing
3856 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3861 bool moving_arg = false;
3862 bool need_closing = false;
3863 bool is_rtl = isRightToLeftPar(bparams);
3865 if (is_rtl != parent_is_rtl) {
3870 need_closing = true;
3873 //BufferParams * params = ¤t_view->buffer()->params;
3874 bool footer_in_body = true;
3875 switch (footnotekind) {
3876 case LyXParagraph::FOOTNOTE:
3877 if (style.intitle) {
3878 os << "\\thanks{\n";
3879 footer_in_body = false;
3882 if (foot_count == -1) {
3883 // we're at depth 0 so we can use:
3884 os << "\\footnote{%\n";
3885 footer_in_body = false;
3887 os << "\\footnotemark{}%\n";
3889 // we only need this when there are
3890 // multiple footnotes
3891 os << "\\stepcounter{footnote}";
3893 os << "\\footnotetext{%\n";
3894 foot_texrow.start(this, 0);
3895 foot_texrow.newline();
3900 case LyXParagraph::MARGIN:
3901 os << "\\marginpar{\n";
3903 case LyXParagraph::FIG:
3904 if (pextra_type == PEXTRA_FLOATFLT
3905 && (!pextra_width.empty()
3906 || !pextra_widthp.empty())) {
3907 if (!pextra_width.empty())
3908 os << "\\begin{floatingfigure}{"
3909 << pextra_width << "}\n";
3911 os << "\\begin{floatingfigure}{"
3912 << atoi(pextra_widthp.c_str())/100.0
3913 << "\\textwidth}\n";
3915 os << "\\begin{figure}";
3916 if (!bparams.float_placement.empty()) {
3917 os << '[' << bparams.float_placement << "]\n";
3923 case LyXParagraph::TAB:
3924 os << "\\begin{table}";
3925 if (!bparams.float_placement.empty()) {
3926 os << '[' << bparams.float_placement << "]\n";
3931 case LyXParagraph::WIDE_FIG:
3932 os << "\\begin{figure*}";
3933 if (!bparams.float_placement.empty()) {
3934 os << '[' << bparams.float_placement << "]\n";
3939 case LyXParagraph::WIDE_TAB:
3940 os << "\\begin{table*}";
3941 if (!bparams.float_placement.empty()) {
3942 os << '[' << bparams.float_placement << "]\n";
3947 case LyXParagraph::ALGORITHM:
3948 os << "\\begin{algorithm}\n";
3953 if (footnotekind != LyXParagraph::FOOTNOTE
3954 || !footer_in_body) {
3955 // Process text for all floats except footnotes in body
3957 LyXLayout const & style =
3959 .Style(bparams.textclass, par->layout);
3961 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3963 if (style.isEnvironment()
3964 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3965 // Allows the use of minipages within float
3966 // environments. Shouldn't be circular because
3967 // we don't support footnotes inside
3968 // floats (yet). ARRae
3969 par = par->TeXEnvironment(buf, bparams, os,
3974 par = par->TeXOnePar(buf, bparams,
3975 os, texrow, moving_arg,
3980 if (par && !par->IsDummy() && par->depth > depth) {
3981 par = par->TeXDeeper(buf, bparams, os, texrow,
3985 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3987 // process footnotes > depth 0 or in environments separately
3988 // NOTE: Currently don't support footnotes within footnotes
3989 // even though that is possible using the \footnotemark
3991 std::ostringstream dummy;
3995 TexRow dummy_texrow;
3996 int dummy_count = 0;
3998 LyXLayout const & style =
4000 .Style(bparams.textclass, par->layout);
4002 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4004 if (style.isEnvironment()
4005 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4006 // Allows the use of minipages within float
4007 // environments. Shouldn't be circular because
4008 // we don't support footnotes inside
4009 // floats (yet). ARRae
4010 par = par->TeXEnvironment(buf, bparams,
4012 dummy, dummy_texrow,
4015 par = par->TeXOnePar(buf, bparams,
4018 dummy, dummy_texrow,
4022 if (par && !par->IsDummy() && par->depth > depth) {
4023 par = par->TeXDeeper(buf, bparams,
4025 dummy, dummy_texrow,
4029 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4031 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4032 "Footnote in a Footnote -- not supported"
4035 #ifndef HAVE_OSTREAM
4036 delete [] dummy.str();
4040 switch (footnotekind) {
4041 case LyXParagraph::FOOTNOTE:
4042 if (footer_in_body) {
4043 // This helps tell which of the multiple
4044 // footnotetexts an error was in.
4046 foot_texrow.newline();
4051 case LyXParagraph::MARGIN:
4054 case LyXParagraph::FIG:
4055 if (pextra_type == PEXTRA_FLOATFLT
4056 && (!pextra_width.empty()
4057 || !pextra_widthp.empty()))
4058 os << "\\end{floatingfigure}";
4060 os << "\\end{figure}";
4062 case LyXParagraph::TAB:
4063 os << "\\end{table}";
4065 case LyXParagraph::WIDE_FIG:
4066 os << "\\end{figure*}";
4068 case LyXParagraph::WIDE_TAB:
4069 os << "\\end{table*}";
4071 case LyXParagraph::ALGORITHM:
4072 os << "\\end{algorithm}";
4079 if (footnotekind != LyXParagraph::FOOTNOTE
4080 && footnotekind != LyXParagraph::MARGIN) {
4081 // we need to ensure that real floats like tables and figures
4082 // have their \end{} on a line of their own otherwise we can
4083 // get incorrect results when using the endfloat.sty package.
4088 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4093 bool LyXParagraph::IsDummy() const
4095 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4096 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4100 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4101 int type, char const * width,
4102 char const * widthp)
4105 pextra_width = width;
4106 pextra_widthp = widthp;
4108 if (textclasslist.Style(bparams.textclass,
4109 layout).isEnvironment()) {
4114 while (par && (par->layout == layout)
4115 && (par->depth == depth)) {
4117 par = par->Previous();
4119 par = par->FirstPhysicalPar();
4120 while (par && par->depth > depth) {
4121 par = par->Previous();
4123 par = par->FirstPhysicalPar();
4127 while (par && (par->layout == layout)
4128 && (par->depth == depth)) {
4129 par->pextra_type = type;
4130 par->pextra_width = width;
4131 par->pextra_widthp = widthp;
4132 par = par->NextAfterFootnote();
4133 if (par && (par->depth > depth))
4134 par->SetPExtraType(bparams,
4135 type, width, widthp);
4136 while (par && ((par->depth > depth) || par->IsDummy()))
4137 par = par->NextAfterFootnote();
4143 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4145 if (pextra_type == PEXTRA_NONE)
4148 pextra_type = PEXTRA_NONE;
4149 pextra_width.erase();
4150 pextra_widthp.erase();
4152 if (textclasslist.Style(bparams.textclass,
4153 layout).isEnvironment()) {
4158 while (par && (par->layout == layout)
4159 && (par->depth == depth)) {
4161 par = par->Previous();
4163 par = par->FirstPhysicalPar();
4164 while (par && par->depth > depth) {
4165 par = par->Previous();
4167 par = par->FirstPhysicalPar();
4171 while (par && (par->layout == layout)
4172 && (par->depth == depth)) {
4173 par->pextra_type = PEXTRA_NONE;
4174 par->pextra_width.erase();
4175 par->pextra_widthp.erase();
4176 par = par->NextAfterFootnote();
4177 if (par && (par->depth > depth))
4178 par->UnsetPExtraType(bparams);
4179 while (par && ((par->depth > depth) || par->IsDummy()))
4180 par = par->NextAfterFootnote();
4186 bool LyXParagraph::IsHfill(size_type pos) const
4188 return IsHfillChar(GetChar(pos));
4192 bool LyXParagraph::IsInset(size_type pos) const
4194 return IsInsetChar(GetChar(pos));
4198 bool LyXParagraph::IsFloat(size_type pos) const
4200 return IsFloatChar(GetChar(pos));
4204 bool LyXParagraph::IsNewline(size_type pos) const
4206 return pos >= 0 && IsNewlineChar(GetChar(pos));
4210 bool LyXParagraph::IsSeparator(size_type pos) const
4212 return IsSeparatorChar(GetChar(pos));
4216 bool LyXParagraph::IsLineSeparator(size_type pos) const
4218 return IsLineSeparatorChar(GetChar(pos));
4222 bool LyXParagraph::IsKomma(size_type pos) const
4224 return IsKommaChar(GetChar(pos));
4228 /// Used by the spellchecker
4229 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4231 unsigned char c = GetChar(pos);
4232 if (IsLetterChar(c))
4234 // '\0' is not a letter, allthough every string contains "" (below)
4237 // We want to pass the ' and escape chars to ispell
4238 string extra = lyxrc.isp_esc_chars + '\'';
4242 return contains(extra, ch);
4246 bool LyXParagraph::IsWord(size_type pos ) const
4248 return IsWordChar(GetChar(pos)) ;
4253 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4256 return FirstPhysicalPar()->getParLanguage(bparams);
4257 else if (size() > 0)
4261 return GetFirstFontSettings().language();
4264 for (size_type pos = 0; pos < size(); ++pos)
4266 return GetFontSettings(bparams, pos).language();
4267 return GetFirstFontSettings().language();
4271 return previous->getParLanguage(bparams);
4273 return bparams.language_info;
4277 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4279 return lyxrc.rtl_support && !table
4280 && getParLanguage(bparams)->RightToLeft();
4284 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4285 Language const * from, Language const * to)
4287 for(size_type i = 0; i < size(); ++i) {
4288 LyXFont font = GetFontSettings(bparams, i);
4289 if (font.language() == from) {
4290 font.setLanguage(to);
4297 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4299 Language const * doc_language =
4300 bparams.language_info;
4301 for(size_type i = 0; i < size(); ++i) {
4302 LyXFont font = GetFontSettings(bparams, i);
4303 if (font.language() != doc_language)
4310 // Convert the paragraph to a string.
4311 // Used for building the table of contents
4312 string LyXParagraph::String(Buffer const * buffer, bool label)
4314 BufferParams const & bparams = buffer->params;
4316 if (label && !IsDummy() && !labelstring.empty())
4317 s += labelstring + ' ';
4318 string::size_type len = s.size();
4320 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4321 unsigned char c = GetChar(i);
4324 else if (c == META_INSET &&
4325 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4327 std::ostringstream ost;
4328 GetInset(i)->Ascii(buffer, ost);
4331 GetInset(i)->Ascii(buffer, ost);
4334 s += subst(ost.str(),'\n',' ');
4339 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4340 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4341 s += NextAfterFootnote()->String(buffer, false);
4346 if (isRightToLeftPar(bparams))
4347 reverse(s.begin() + len,s.end());
4353 string LyXParagraph::String(Buffer const * buffer,
4354 LyXParagraph::size_type beg,
4355 LyXParagraph::size_type end)
4362 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4364 if (cell >= table->NumberOfCellsInRow(actcell))
4372 if (beg == 0 && !IsDummy() && !labelstring.empty())
4373 s += labelstring + ' ';
4375 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4376 unsigned char c = GetChar(i);
4379 else if (c == META_INSET) {
4381 std::ostringstream ost;
4382 GetInset(i)->Ascii(buffer, ost);
4385 GetInset(i)->Ascii(buffer, ost);
4389 } else if (table && IsNewlineChar(c)) {
4390 if (cell >= table->NumberOfCellsInRow(actcell)) {
4401 //if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4402 // s += NextAfterFootnote()->String(false);
4408 void LyXParagraph::SetInsetOwner(Inset *i)
4411 for (InsetList::const_iterator cit = insetlist.begin();
4412 cit != insetlist.end(); ++cit) {
4414 (*cit).inset->setOwner(i);
4419 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4422 for (InsetList::const_iterator cit = insetlist.begin();
4423 cit != insetlist.end(); ++cit) {
4425 if ((*cit).inset->IsTextInset()) {
4426 static_cast<UpdatableInset *>
4427 ((*cit).inset)->deleteLyXText(bv);