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 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
135 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
137 // The beginning or the end of a footnote environment?
138 if (footflag != footnoteflag) {
139 footflag = footnoteflag;
141 os << "\n\\begin_float "
142 << string_footnotekinds[footnotekind]
145 os << "\n\\end_float ";
149 // The beginning or end of a deeper (i.e. nested) area?
152 while (depth > dth) {
153 os << "\n\\begin_deeper ";
157 while (depth < dth) {
158 os << "\n\\end_deeper ";
164 // First write the layout
166 << textclasslist.NameOfLayout(params.textclass, layout)
169 // Maybe some vertical spaces.
170 if (added_space_top.kind() != VSpace::NONE)
171 os << "\\added_space_top "
172 << added_space_top.asLyXCommand() << " ";
173 if (added_space_bottom.kind() != VSpace::NONE)
174 os << "\\added_space_bottom "
175 << added_space_bottom.asLyXCommand() << " ";
177 // Maybe the paragraph has special spacing
178 spacing.writeFile(os, true);
180 // The labelwidth string used in lists.
181 if (!labelwidthstring.empty())
182 os << "\\labelwidthstring "
183 << labelwidthstring << '\n';
185 // Lines above or below?
189 os << "\\line_bottom ";
191 // Pagebreaks above or below?
193 os << "\\pagebreak_top ";
194 if (pagebreak_bottom)
195 os << "\\pagebreak_bottom ";
197 // Start of appendix?
198 if (start_of_appendix)
199 os << "\\start_of_appendix ";
206 if (align != LYX_ALIGN_LAYOUT) {
209 case LYX_ALIGN_LEFT: h = 1; break;
210 case LYX_ALIGN_RIGHT: h = 2; break;
211 case LYX_ALIGN_CENTER: h = 3; break;
212 default: h = 0; break;
214 os << "\\align " << string_align[h] << " ";
216 if (pextra_type != PEXTRA_NONE) {
217 os << "\\pextra_type " << pextra_type;
218 if (pextra_type == PEXTRA_MINIPAGE) {
219 os << " \\pextra_alignment "
222 os << " \\pextra_hfill "
224 if (pextra_start_minipage)
225 os << " \\pextra_start_minipage "
226 << pextra_start_minipage;
228 if (!pextra_width.empty()) {
229 os << " \\pextra_width "
230 << VSpace(pextra_width).asLyXCommand();
231 } else if (!pextra_widthp.empty()) {
232 os << " \\pextra_widthp "
238 // Dummy layout. This means that a footnote ended.
239 os << "\n\\end_float ";
240 footflag = LyXParagraph::NO_FOOTNOTE;
243 // It might be a table.
245 os << "\\LyXTable\n";
251 bibkey->Write(buf, os);
253 LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
256 for (size_type i = 0; i < size(); ++i) {
262 // Write font changes
263 LyXFont font2 = GetFontSettings(params, i);
264 if (font2 != font1) {
265 font2.lyxWriteChanges(font1, os);
270 value_type c = GetChar(i);
274 Inset const * inset = GetInset(i);
276 if (inset->DirectWrite()) {
277 // international char, let it write
278 // code directly so it's shorter in
280 inset->Write(buf, os);
282 os << "\n\\begin_inset ";
283 inset->Write(buf, os);
284 os << "\n\\end_inset \n\n";
290 os << "\n\\newline \n";
294 os << "\n\\hfill \n";
298 os << "\n\\backslash \n";
302 if (i + 1 < size() && GetChar(i + 1) == ' ') {
309 if ((column > 70 && c == ' ')
314 // this check is to amend a bug. LyX sometimes
315 // inserts '\0' this could cause problems.
319 lyxerr << "ERROR (LyXParagraph::writeFile):"
320 " NULL char in structure." << endl;
326 // now write the next paragraph
328 next->writeFile(buf, os, params, footflag, dth);
332 void LyXParagraph::validate(LaTeXFeatures & features) const
334 BufferParams const & params = features.bufferParams();
336 // this will be useful later
337 LyXLayout const & layout =
338 textclasslist.Style(params.textclass,
342 if (line_top || line_bottom)
343 features.lyxline = true;
344 if (!spacing.isDefault())
345 features.setspace = true;
348 features.layout[GetLayout()] = true;
351 Language const * doc_language = params.language_info;
353 for (FontList::const_iterator cit = fontlist.begin();
354 cit != fontlist.end(); ++cit) {
355 if ((*cit).font.noun() == LyXFont::ON) {
356 lyxerr[Debug::LATEX] << "font.noun: "
357 << (*cit).font.noun()
359 features.noun = true;
360 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
361 << (*cit).font.stateText(0)
364 switch ((*cit).font.color()) {
366 case LColor::inherit:
370 features.color = true;
371 lyxerr[Debug::LATEX] << "Color enabled. Font: "
372 << (*cit).font.stateText(0)
376 Language const * language = (*cit).font.language();
377 if (language != doc_language) {
378 features.UsedLanguages.insert(language);
379 lyxerr[Debug::LATEX] << "Found language "
380 << language->lang() << endl;
385 for (InsetList::const_iterator cit = insetlist.begin();
386 cit != insetlist.end(); ++cit) {
388 (*cit).inset->Validate(features);
391 if (table && table->IsLongTable())
392 features.longtable = true;
393 if (pextra_type == PEXTRA_INDENT)
394 features.LyXParagraphIndent = true;
395 if (pextra_type == PEXTRA_FLOATFLT)
396 features.floatflt = true;
397 if (layout.needprotect
398 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
399 features.NeedLyXFootnoteCode = true;
400 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
401 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
402 features.NeedLyXMinipageIndent = true;
403 if (table && table->NeedRotating())
404 features.rotating = true;
405 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
406 features.algorithm = true;
410 // First few functions needed for cut and paste and paragraph breaking.
411 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
412 LyXParagraph::size_type pos) const
414 minibuffer_char = GetChar(pos);
415 minibuffer_font = GetFontSettings(bparams, pos);
416 minibuffer_inset = 0;
417 if (minibuffer_char == LyXParagraph::META_INSET) {
419 minibuffer_inset = GetInset(pos)->Clone();
421 minibuffer_inset = 0;
422 minibuffer_char = ' ';
423 // This reflects what GetInset() does (ARRae)
429 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
430 LyXParagraph::size_type pos)
432 minibuffer_char = GetChar(pos);
433 minibuffer_font = GetFontSettings(bparams, pos);
434 minibuffer_inset = 0;
435 if (minibuffer_char == LyXParagraph::META_INSET) {
437 minibuffer_inset = GetInset(pos);
438 // This is a little hack since I want exactly
439 // the inset, not just a clone. Otherwise
440 // the inset would be deleted when calling Erase(pos)
442 InsetTable search_elem(pos, 0);
443 InsetList::iterator it =
444 lower_bound(insetlist.begin(),
446 search_elem, matchIT());
447 if (it != insetlist.end() && (*it).pos == pos)
450 minibuffer_inset = 0;
451 minibuffer_char = ' ';
452 // This reflects what GetInset() does (ARRae)
457 // Erase(pos); now the caller is responsible for that.
461 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
463 if ((minibuffer_char == LyXParagraph::META_INSET) &&
464 !InsertInsetAllowed(minibuffer_inset))
466 if (minibuffer_char == LyXParagraph::META_INSET)
467 InsertInset(pos, minibuffer_inset, minibuffer_font);
469 InsertChar(pos, minibuffer_char, minibuffer_font);
477 void LyXParagraph::Clear()
482 pagebreak_top = false;
483 pagebreak_bottom = false;
485 added_space_top = VSpace(VSpace::NONE);
486 added_space_bottom = VSpace(VSpace::NONE);
487 spacing.set(Spacing::Default);
489 align = LYX_ALIGN_LAYOUT;
493 pextra_type = PEXTRA_NONE;
494 pextra_width.erase();
495 pextra_widthp.erase();
496 pextra_alignment = MINIPAGE_ALIGN_TOP;
497 pextra_hfill = false;
498 pextra_start_minipage = false;
501 labelwidthstring.erase();
505 start_of_appendix = false;
509 // the destructor removes the new paragraph from the list
510 LyXParagraph::~LyXParagraph()
513 previous->next = next;
515 next->previous = previous;
517 for (InsetList::iterator it = insetlist.begin();
518 it != insetlist.end(); ++it) {
522 /* table stuff -- begin*/
524 /* table stuff -- end*/
530 //lyxerr << "LyXParagraph::paragraph_id = "
531 // << LyXParagraph::paragraph_id << endl;
535 void LyXParagraph::Erase(LyXParagraph::size_type pos)
537 // > because last is the next unused position, and you can
538 // use it if you want
541 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
542 NextAfterFootnote()->Erase(pos - text.size() - 1);
545 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
546 "position does not exist." << endl;
549 if (pos < size()) { // last is free for insertation, but should be empty
550 // if it is an inset, delete the inset entry
551 if (text[pos] == LyXParagraph::META_INSET) {
553 InsetTable search_inset(pos, 0);
554 InsetList::iterator it =
555 lower_bound(insetlist.begin(),
557 search_inset, matchIT());
558 if (it != insetlist.end() && (*it).pos == pos) {
563 text.erase(text.begin() + pos);
565 // Erase entries in the tables.
566 FontTable search_font(pos, LyXFont());
568 FontList::iterator it =
569 lower_bound(fontlist.begin(),
571 search_font, matchFT());
572 if (it != fontlist.end() && (*it).pos == pos &&
574 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
575 // If it is a multi-character font
576 // entry, we just make it smaller
577 // (see update below), otherwise we
579 unsigned int i = it - fontlist.begin();
580 fontlist.erase(fontlist.begin() + i);
581 it = fontlist.begin() + i;
582 if (i > 0 && i < fontlist.size() &&
583 fontlist[i-1].font == fontlist[i].font) {
584 fontlist.erase(fontlist.begin() + i-1);
585 it = fontlist.begin() + i-1;
589 // Update all other entries.
590 for (; it != fontlist.end(); ++it)
593 // Update the inset table.
594 InsetTable search_inset(pos, 0);
595 for (InsetList::iterator it =
596 upper_bound(insetlist.begin(),
598 search_inset, matchIT());
599 it != insetlist.end(); ++it)
602 lyxerr << "ERROR (LyXParagraph::Erase): "
603 "can't erase non-existant char." << endl;
608 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
609 LyXParagraph::value_type c)
611 LyXFont f(LyXFont::ALL_INHERIT);
612 InsertChar(pos, c, f);
616 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
617 LyXParagraph::value_type c,
618 LyXFont const & font)
620 // > because last is the next unused position, and you can
621 // use it if you want
625 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
626 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
630 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
631 "position does not exist." << endl;
634 text.insert(text.begin() + pos, c);
635 // Update the font table.
636 FontTable search_font(pos, LyXFont());
637 for (FontList::iterator it = lower_bound(fontlist.begin(),
639 search_font, matchFT());
640 it != fontlist.end(); ++it)
643 // Update the inset table.
644 InsetTable search_inset(pos, 0);
645 for (InsetList::iterator it = lower_bound(insetlist.begin(),
647 search_inset, matchIT());
648 it != insetlist.end(); ++it)
655 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
658 LyXFont f(LyXFont::ALL_INHERIT);
659 InsertInset(pos, inset, f);
663 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
664 Inset * inset, LyXFont const & font)
668 // > because last is the next unused position, and you can
669 // use it if you want
673 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
675 ->InsertInset(pos - text.size() - 1,
679 lyxerr << "ERROR (LyXParagraph::InsertInset): "
680 "position does not exist: " << pos << endl;
684 InsertChar(pos, META_INSET, font);
685 Assert(text[pos] == META_INSET);
687 // Add a new entry in the inset table.
688 InsetTable search_inset(pos, 0);
689 InsetList::iterator it = lower_bound(insetlist.begin(),
691 search_inset, matchIT());
692 if (it != insetlist.end() && (*it).pos == pos)
693 lyxerr << "ERROR (LyXParagraph::InsertInset): "
694 "there is an inset in position: " << pos << endl;
696 insetlist.insert(it, InsetTable(pos, inset));
698 inset->setOwner(inset_owner);
702 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
704 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
707 return inset_owner->InsertInsetAllowed(inset);
712 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
717 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
718 return NextAfterFootnote()
719 ->GetInset(pos - text.size() - 1);
722 lyxerr << "ERROR (LyXParagraph::GetInset): "
723 "position does not exist: "
729 InsetTable search_inset(pos, 0);
730 InsetList::iterator it = lower_bound(insetlist.begin(),
732 search_inset, matchIT());
733 if (it != insetlist.end() && (*it).pos == pos)
736 lyxerr << "ERROR (LyXParagraph::GetInset): "
737 "Inset does not exist: " << pos << endl;
740 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
741 // Did this commenting out introduce a bug? So far I have not
742 // see any, please enlighten me. (Lgb)
743 // My guess is that since the inset does not exist, we might
744 // as well replace it with a space to prevent craches. (Asger)
749 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
754 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
755 return NextAfterFootnote()
756 ->GetInset(pos - text.size() - 1);
759 lyxerr << "ERROR (LyXParagraph::GetInset): "
760 "position does not exist: "
766 InsetTable search_inset(pos, 0);
767 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
769 search_inset, matchIT());
770 if (cit != insetlist.end() && (*cit).pos == pos)
773 lyxerr << "ERROR (LyXParagraph::GetInset): "
774 "Inset does not exist: " << pos << endl;
776 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
777 // Did this commenting out introduce a bug? So far I have not
778 // see any, please enlighten me. (Lgb)
779 // My guess is that since the inset does not exist, we might
780 // as well replace it with a space to prevent craches. (Asger)
785 // Gets uninstantiated font setting at position.
786 // Optimized after profiling. (Asger)
787 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
788 LyXParagraph::size_type pos) const
791 FontTable search_font(pos, LyXFont());
792 FontList::const_iterator cit = lower_bound(fontlist.begin(),
794 search_font, matchFT());
795 if (cit != fontlist.end())
798 // > because last is the next unused position, and you can
799 // use it if you want
800 else if (pos > size()) {
803 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
804 return NextAfterFootnote()
805 ->GetFontSettings(bparams,
806 pos - text.size() - 1);
809 // Why is it an error to ask for the font of a
810 // position that does not exist? Would it be
811 // enough for this to be enabled on debug?
812 // We want strict error checking, but it's ok to only
813 // have it when debugging. (Asger)
814 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
815 "position does not exist. "
816 << pos << " (" << static_cast<int>(pos)
818 } else if (pos > 0) {
819 return GetFontSettings(bparams, pos - 1);
820 } else // pos = size() = 0
821 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
823 return LyXFont(LyXFont::ALL_INHERIT);
826 // Gets uninstantiated font setting at position 0
827 LyXFont LyXParagraph::GetFirstFontSettings() const
830 if (!fontlist.empty())
831 return fontlist[0].font;
835 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
836 return NextAfterFootnote()->GetFirstFontSettings();
838 return LyXFont(LyXFont::ALL_INHERIT);
842 // Gets the fully instantiated font at a given position in a paragraph
843 // This is basically the same function as LyXText::GetFont() in text2.C.
844 // The difference is that this one is used for generating the LaTeX file,
845 // and thus cosmetic "improvements" are disallowed: This has to deliver
846 // the true picture of the buffer. (Asger)
847 // If position is -1, we get the layout font of the paragraph.
848 // If position is -2, we get the font of the manual label of the paragraph.
849 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
850 LyXParagraph::size_type pos) const
853 LyXLayout const & layout =
854 textclasslist.Style(bparams.textclass,
856 LyXParagraph::size_type main_body = 0;
857 if (layout.labeltype == LABEL_MANUAL)
858 main_body = BeginningOfMainBody();
863 layoutfont = layout.labelfont;
865 layoutfont = layout.font;
866 tmpfont = GetFontSettings(bparams, pos);
867 tmpfont.realize(layoutfont);
869 // process layoutfont for pos == -1 and labelfont for pos < -1
871 tmpfont = layout.font;
873 tmpfont = layout.labelfont;
874 tmpfont.setLanguage(getParLanguage(bparams));
877 // check for environment font information
878 char par_depth = GetDepth();
879 LyXParagraph const * par = this;
880 while (par && par_depth && !tmpfont.resolved()) {
881 par = par->DepthHook(par_depth - 1);
883 tmpfont.realize(textclasslist.
884 Style(bparams.textclass,
885 par->GetLayout()).font);
886 par_depth = par->GetDepth();
890 tmpfont.realize(textclasslist
891 .TextClass(bparams.textclass)
897 /// Returns the height of the highest font in range
899 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
900 LyXParagraph::size_type endpos) const
902 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
903 if (fontlist.empty())
906 FontTable end_search(endpos, LyXFont());
907 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
909 end_search, matchFT());
910 if (end_it != fontlist.end())
913 FontTable start_search(startpos, LyXFont());
914 for (FontList::const_iterator cit =
915 lower_bound(fontlist.begin(),
917 start_search, matchFT());
918 cit != end_it; ++cit) {
919 LyXFont::FONT_SIZE size = (*cit).font.size();
920 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
927 LyXParagraph::value_type
928 LyXParagraph::GetChar(LyXParagraph::size_type pos)
935 // > because last is the next unused position, and you can
936 // use it if you want
937 else if (pos > size()) {
939 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
940 return NextAfterFootnote()
941 ->GetChar(pos - text.size() - 1);
945 lyxerr << "ERROR (LyXParagraph::GetChar): "
946 "position does not exist."
947 << pos << " (" << static_cast<int>(pos)
949 // Assert(false); // This triggers sometimes...
958 // We should have a footnote environment.
959 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
960 // Notice that LyX does request the
961 // last char from time to time. (Asger)
962 //lyxerr << "ERROR (LyXParagraph::GetChar): "
963 // "expected footnote." << endl;
966 switch (next->footnotekind) {
967 case LyXParagraph::FOOTNOTE:
968 return LyXParagraph::META_FOOTNOTE;
969 case LyXParagraph::MARGIN:
970 return LyXParagraph::META_MARGIN;
971 case LyXParagraph::FIG:
972 case LyXParagraph::WIDE_FIG:
973 return LyXParagraph::META_FIG;
974 case LyXParagraph::TAB:
975 case LyXParagraph::WIDE_TAB:
976 return LyXParagraph::META_TAB;
977 case LyXParagraph::ALGORITHM:
978 return LyXParagraph::META_ALGORITHM;
980 return '\0'; // to shut up gcc
986 LyXParagraph::value_type
987 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
994 // > because last is the next unused position, and you can
995 // use it if you want
996 else if (pos > size()) {
998 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
999 return NextAfterFootnote()
1000 ->GetChar(pos - text.size() - 1);
1004 lyxerr << "ERROR (LyXParagraph::GetChar const): "
1005 "position does not exist."
1006 << pos << " (" << static_cast<int>(pos)
1014 // We should have a footnote environment.
1015 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1016 // Notice that LyX does request the
1017 // last char from time to time. (Asger)
1018 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1019 // "expected footnote." << endl;
1022 switch (next->footnotekind) {
1023 case LyXParagraph::FOOTNOTE:
1024 return LyXParagraph::META_FOOTNOTE;
1025 case LyXParagraph::MARGIN:
1026 return LyXParagraph::META_MARGIN;
1027 case LyXParagraph::FIG:
1028 case LyXParagraph::WIDE_FIG:
1029 return LyXParagraph::META_FIG;
1030 case LyXParagraph::TAB:
1031 case LyXParagraph::WIDE_TAB:
1032 return LyXParagraph::META_TAB;
1033 case LyXParagraph::ALGORITHM:
1034 return LyXParagraph::META_ALGORITHM;
1036 return '\0'; // to shut up gcc
1042 // return an string of the current word, and the end of the word in lastpos.
1043 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1047 // the current word is defined as starting at the first character
1048 // from the immediate left of lastpospos which meets the definition
1049 // of IsLetter(), continuing to the last character to the right
1050 // of this meeting IsLetter.
1056 // move back until we have a letter
1058 //there's no real reason to have firstpos & lastpos as
1059 //separate variables as this is written, but maybe someon
1060 // will want to return firstpos in the future.
1062 //since someone might have typed a punctuation first
1063 int firstpos = lastpos;
1065 while ((firstpos >= 0) && !IsLetter(firstpos))
1068 // now find the beginning by looking for a nonletter
1070 while ((firstpos>= 0) && IsLetter(firstpos))
1073 // the above is now pointing to the preceeding non-letter
1077 // so copy characters into theword until we get a nonletter
1078 // note that this can easily exceed lastpos, wich means
1079 // that if used in the middle of a word, the whole word
1082 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1089 LyXParagraph::size_type LyXParagraph::Last() const
1092 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1093 return text.size() + NextAfterFootnote()->Last() + 1;
1094 // the 1 is the symbol
1102 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1104 // > because last is the next unused position, and you can
1105 // use it if you want
1109 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1110 return NextAfterFootnote()
1111 ->ParFromPos(pos - text.size() - 1);
1114 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1115 "position does not exist." << endl;
1122 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1124 // > because last is the next unused position, and you can
1125 // use it if you want
1129 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1130 return NextAfterFootnote()
1131 ->PositionInParFromPos(pos - text.size() - 1);
1135 "ERROR (LyXParagraph::PositionInParFromPos): "
1136 "position does not exist." << endl;
1144 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1145 LyXFont const & font)
1147 // > because last is the next unused position, and you can
1148 // use it if you want
1152 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1153 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1157 lyxerr << "ERROR (LyXParagraph::SetFont): "
1158 "position does not exist." << endl;
1163 // First, reduce font against layout/label font
1164 // Update: The SetCharFont() routine in text2.C already
1165 // reduces font, so we don't need to do that here. (Asger)
1166 // No need to simplify this because it will disappear
1167 // in a new kernel. (Asger)
1168 // Next search font table
1170 FontTable search_font(pos, LyXFont());
1171 FontList::iterator it = lower_bound(fontlist.begin(),
1173 search_font, matchFT());
1174 unsigned int i = it - fontlist.begin();
1175 bool notfound = it == fontlist.end();
1177 if (!notfound && fontlist[i].font == font)
1180 bool begin = pos == 0 || notfound ||
1181 (i > 0 && fontlist[i-1].pos == pos - 1);
1182 // Is position pos is a beginning of a font block?
1183 bool end = !notfound && fontlist[i].pos == pos;
1184 // Is position pos is the end of a font block?
1185 if (begin && end) { // A single char block
1186 if (i+1 < fontlist.size() &&
1187 fontlist[i+1].font == font) {
1188 // Merge the singleton block with the next block
1189 fontlist.erase(fontlist.begin() + i);
1190 if (i > 0 && fontlist[i-1].font == font)
1191 fontlist.erase(fontlist.begin() + i-1);
1192 } else if (i > 0 && fontlist[i-1].font == font) {
1193 // Merge the singleton block with the previous block
1194 fontlist[i-1].pos = pos;
1195 fontlist.erase(fontlist.begin() + i);
1197 fontlist[i].font = font;
1199 if (i > 0 && fontlist[i-1].font == font)
1200 fontlist[i-1].pos = pos;
1202 fontlist.insert(fontlist.begin() + i,
1203 FontTable(pos, font));
1205 fontlist[i].pos = pos - 1;
1206 if (!(i+1 < fontlist.size() &&
1207 fontlist[i+1].font == font))
1208 fontlist.insert(fontlist.begin() + i+1,
1209 FontTable(pos, font));
1210 } else { // The general case. The block is splitted into 3 blocks
1211 fontlist.insert(fontlist.begin() + i,
1212 FontTable(pos - 1, fontlist[i].font));
1213 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1218 // This function is able to hide closed footnotes.
1219 LyXParagraph * LyXParagraph::Next()
1222 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1223 LyXParagraph * tmp = next;
1225 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1227 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1228 return tmp->Next(); /* there can be more than one
1229 footnote in a logical
1232 return next; // This should never happen!
1239 LyXParagraph * LyXParagraph::NextAfterFootnote()
1242 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1243 LyXParagraph * tmp = next;
1244 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1246 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1247 return tmp; /* there can be more than one footnote
1248 in a logical paragraph */
1250 return next; // This should never happen!
1257 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1260 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1261 LyXParagraph * tmp = next;
1262 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
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 next; // This should never happen!
1275 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1279 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1281 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1282 tmp = tmp->previous;
1283 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1284 return tmp; /* there can be more than one footnote
1285 in a logical paragraph */
1287 return previous; // This should never happen!
1294 LyXParagraph * LyXParagraph::LastPhysicalPar()
1297 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1300 LyXParagraph * tmp = this;
1302 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1303 tmp = tmp->NextAfterFootnote();
1311 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1314 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1317 LyXParagraph const * tmp = this;
1319 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1320 tmp = tmp->NextAfterFootnote();
1328 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1333 LyXParagraph * tmppar = this;
1337 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1338 tmppar = tmppar->previous;
1350 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1355 LyXParagraph const * tmppar = this;
1359 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1360 tmppar = tmppar->previous;
1372 // This function is able to hide closed footnotes.
1373 LyXParagraph * LyXParagraph::Previous()
1375 LyXParagraph * tmp = previous;
1381 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1382 tmp = tmp->previous;
1384 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1385 tmp = tmp->previous;
1386 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1387 return tmp->next->Previous();
1397 // This function is able to hide closed footnotes.
1398 LyXParagraph const * LyXParagraph::Previous() const
1400 LyXParagraph * tmp = previous;
1405 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1406 tmp = tmp->previous;
1408 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1409 tmp = tmp->previous;
1410 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1411 return tmp->next->Previous();
1421 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1422 LyXParagraph::size_type pos,
1425 size_type i, j, pos_end, pos_first;
1426 // create a new paragraph
1427 LyXParagraph * par = ParFromPos(pos);
1428 LyXParagraph * firstpar = FirstPhysicalPar();
1430 LyXParagraph * tmp = new LyXParagraph(par);
1433 tmp->footnoteflag = footnoteflag;
1434 tmp->footnotekind = footnotekind;
1436 // this is an idea for a more userfriendly layout handling, I will
1437 // see what the users say
1439 // layout stays the same with latex-environments
1441 tmp->SetOnlyLayout(bparams, firstpar->layout);
1442 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1445 if (Last() > pos || !Last() || flag == 2) {
1446 tmp->SetOnlyLayout(bparams, firstpar->layout);
1447 tmp->align = firstpar->align;
1448 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1450 tmp->line_bottom = firstpar->line_bottom;
1451 firstpar->line_bottom = false;
1452 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1453 firstpar->pagebreak_bottom = false;
1454 tmp->added_space_bottom = firstpar->added_space_bottom;
1455 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1457 tmp->depth = firstpar->depth;
1458 tmp->noindent = firstpar->noindent;
1460 // copy everything behind the break-position
1461 // to the new paragraph
1463 while (ParFromPos(pos_first) != par)
1466 pos_end = pos_first + par->text.size() - 1;
1468 for (i = j = pos; i <= pos_end; ++i) {
1469 par->CutIntoMinibuffer(bparams, i - pos_first);
1470 if (tmp->InsertFromMinibuffer(j - pos))
1473 tmp->text.resize(tmp->text.size());
1474 for (i = pos_end; i >= pos; --i)
1475 par->Erase(i - pos_first);
1477 par->text.resize(par->text.size());
1480 // just an idea of me
1482 tmp->line_top = firstpar->line_top;
1483 tmp->pagebreak_top = firstpar->pagebreak_top;
1484 tmp->added_space_top = firstpar->added_space_top;
1485 tmp->bibkey = firstpar->bibkey;
1487 // layout stays the same with latex-environments
1489 firstpar->SetOnlyLayout(bparams, tmp->layout);
1490 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1491 firstpar->depth = tmp->depth;
1497 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1499 par = par->FirstPhysicalPar();
1501 footnoteflag = par->footnoteflag;
1502 footnotekind = par->footnotekind;
1504 layout = par->layout;
1505 align = par-> align;
1506 SetLabelWidthString(par->labelwidthstring);
1508 line_bottom = par->line_bottom;
1509 pagebreak_bottom = par->pagebreak_bottom;
1510 added_space_bottom = par->added_space_bottom;
1512 line_top = par->line_top;
1513 pagebreak_top = par->pagebreak_top;
1514 added_space_top = par->added_space_top;
1516 spacing = par->spacing;
1518 pextra_type = par->pextra_type;
1519 pextra_width = par->pextra_width;
1520 pextra_widthp = par->pextra_widthp;
1521 pextra_alignment = par->pextra_alignment;
1522 pextra_hfill = par->pextra_hfill;
1523 pextra_start_minipage = par->pextra_start_minipage;
1525 noindent = par->noindent;
1531 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1533 LyXParagraph * tmppar = this;
1536 && tmppar->previous->footnoteflag ==
1537 LyXParagraph::CLOSED_FOOTNOTE)
1538 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1539 tmppar = tmppar->previous;
1542 return this; // This should never happen!
1549 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1551 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1555 if (!IsDummy() && !table){
1557 && (IsNewline(0) || IsLineSeparator(0))){
1566 LyXParagraph * LyXParagraph::Clone() const
1568 // create a new paragraph
1569 LyXParagraph * result = new LyXParagraph;
1571 result->MakeSameLayout(this);
1573 // this is because of the dummy layout of the paragraphs that
1575 result->layout = layout;
1578 /* table stuff -- begin*/
1580 result->table = table->Clone();
1583 /* table stuff -- end*/
1585 result->inset_owner = inset_owner;
1588 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1591 // copy everything behind the break-position to the new paragraph
1593 result->text = text;
1594 result->fontlist = fontlist;
1595 result->insetlist = insetlist;
1596 for (InsetList::iterator it = result->insetlist.begin();
1597 it != result->insetlist.end(); ++it)
1598 (*it).inset = (*it).inset->Clone();
1603 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1605 par = par->FirstPhysicalPar();
1609 par->footnoteflag == footnoteflag &&
1610 par->footnotekind == footnotekind &&
1612 par->layout == layout &&
1614 par->align == align &&
1616 par->line_bottom == line_bottom &&
1617 par->pagebreak_bottom == pagebreak_bottom &&
1618 par->added_space_bottom == added_space_bottom &&
1620 par->line_top == line_top &&
1621 par->pagebreak_top == pagebreak_top &&
1622 par->added_space_top == added_space_top &&
1624 par->spacing == spacing &&
1626 par->pextra_type == pextra_type &&
1627 par->pextra_width == pextra_width &&
1628 par->pextra_widthp == pextra_widthp &&
1629 par->pextra_alignment == pextra_alignment &&
1630 par->pextra_hfill == pextra_hfill &&
1631 par->pextra_start_minipage == pextra_start_minipage &&
1633 par->table == table && // what means: NO TABLE AT ALL
1636 par->noindent == noindent &&
1637 par->depth == depth);
1641 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1642 LyXParagraph::size_type pos)
1644 // create a new paragraph
1645 LyXParagraph * par = ParFromPos(pos);
1647 LyXParagraph * tmp = new LyXParagraph(par);
1649 tmp->MakeSameLayout(par);
1651 // When can pos < Last()?
1652 // I guess pos == Last() is possible.
1654 // copy everything behind the break-position to the new
1656 size_type pos_first = 0;
1657 while (ParFromPos(pos_first) != par)
1659 size_type pos_end = pos_first + par->text.size() - 1;
1662 for (i = j = pos; i <= pos_end; ++i) {
1663 par->CutIntoMinibuffer(bparams, i - pos_first);
1664 if (tmp->InsertFromMinibuffer(j - pos))
1667 tmp->text.resize(tmp->text.size());
1668 for (size_type i = pos_end; i >= pos; --i)
1669 par->Erase(i - pos_first);
1671 par->text.resize(par->text.size());
1676 // Be carefull, this does not make any check at all.
1677 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1679 // copy the next paragraph to this one
1680 LyXParagraph * the_next = Next();
1682 LyXParagraph * firstpar = FirstPhysicalPar();
1684 // first the DTP-stuff
1685 firstpar->line_bottom = the_next->line_bottom;
1686 firstpar->added_space_bottom = the_next->added_space_bottom;
1687 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1689 size_type pos_end = the_next->text.size() - 1;
1690 size_type pos_insert = Last();
1692 // ok, now copy the paragraph
1694 for (i = j = 0; i <= pos_end; ++i) {
1695 the_next->CutIntoMinibuffer(bparams, i);
1696 if (InsertFromMinibuffer(pos_insert + j))
1700 // delete the next paragraph
1701 LyXParagraph * ppar = the_next->previous;
1702 LyXParagraph * npar = the_next->next;
1709 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1711 LyXParagraph * par = ParFromPos(pos);
1713 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1714 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1720 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1722 LyXParagraph * par = ParFromPos(pos);
1724 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1725 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1731 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1733 LyXParagraph const * par = this;
1734 int par_depth = GetDepth();
1736 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1738 textclasslist.Style(bparams.textclass,
1739 layout).endlabeltype;
1740 if (endlabeltype != END_LABEL_NO_LABEL) {
1741 LyXParagraph const * last = this;
1742 if( footnoteflag == NO_FOOTNOTE)
1743 last = LastPhysicalPar();
1744 else if (next->footnoteflag == NO_FOOTNOTE)
1745 return endlabeltype;
1747 if (!last || !last->next)
1748 return endlabeltype;
1750 int next_depth = last->next->GetDepth();
1751 if (par_depth > next_depth ||
1752 (par_depth == next_depth && layout != last->next->GetLayout() ))
1753 return endlabeltype;
1758 par = par->DepthHook(par_depth - 1);
1760 par_depth = par->GetDepth();
1762 return END_LABEL_NO_LABEL;
1766 LyXTextClass::size_type LyXParagraph::GetLayout() const
1768 return FirstPhysicalPar()->layout;
1772 char LyXParagraph::GetDepth() const
1774 return FirstPhysicalPar()->depth;
1778 char LyXParagraph::GetAlign() const
1780 return FirstPhysicalPar()->align;
1784 string LyXParagraph::GetLabelstring() const
1786 return FirstPhysicalPar()->labelstring;
1790 int LyXParagraph::GetFirstCounter(int i) const
1792 return FirstPhysicalPar()->counter_[i];
1796 // the next two functions are for the manual labels
1797 string LyXParagraph::GetLabelWidthString() const
1799 if (!FirstPhysicalPar()->labelwidthstring.empty())
1800 return FirstPhysicalPar()->labelwidthstring;
1802 return _("Senseless with this layout!");
1806 void LyXParagraph::SetLabelWidthString(string const & s)
1808 LyXParagraph * par = FirstPhysicalPar();
1810 par->labelwidthstring = s;
1814 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1815 LyXTextClass::size_type new_layout)
1817 LyXParagraph * par = FirstPhysicalPar();
1818 LyXParagraph * ppar = 0;
1819 LyXParagraph * npar = 0;
1821 par->layout = new_layout;
1823 /* table stuff -- begin*/
1826 /* table stuff -- end*/
1828 if (par->pextra_type == PEXTRA_NONE) {
1829 if (par->Previous()) {
1830 ppar = par->Previous()->FirstPhysicalPar();
1833 && (ppar->depth > par->depth))
1834 ppar = ppar->Previous()->FirstPhysicalPar();
1837 npar = par->Next()->NextAfterFootnote();
1840 && (npar->depth > par->depth))
1841 npar = npar->Next()->NextAfterFootnote();
1843 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1845 p1 = ppar->pextra_width,
1846 p2 = ppar->pextra_widthp;
1847 ppar->SetPExtraType(bparams, ppar->pextra_type,
1848 p1.c_str(), p2.c_str());
1850 if ((par->pextra_type == PEXTRA_NONE) &&
1851 npar && (npar->pextra_type != PEXTRA_NONE)) {
1853 p1 = npar->pextra_width,
1854 p2 = npar->pextra_widthp;
1855 npar->SetPExtraType(bparams, npar->pextra_type,
1856 p1.c_str(), p2.c_str());
1862 void LyXParagraph::SetLayout(BufferParams const & bparams,
1863 LyXTextClass::size_type new_layout)
1866 * par = FirstPhysicalPar(),
1870 par->layout = new_layout;
1871 par->labelwidthstring.erase();
1872 par->align = LYX_ALIGN_LAYOUT;
1873 par->added_space_top = VSpace(VSpace::NONE);
1874 par->added_space_bottom = VSpace(VSpace::NONE);
1875 par->spacing.set(Spacing::Default);
1878 /* table stuff -- begin*/
1881 /* table stuff -- end*/
1883 if (par->pextra_type == PEXTRA_NONE) {
1884 if (par->Previous()) {
1885 ppar = par->Previous()->FirstPhysicalPar();
1888 && (ppar->depth > par->depth))
1889 ppar = ppar->Previous()->FirstPhysicalPar();
1892 npar = par->Next()->NextAfterFootnote();
1895 && (npar->depth > par->depth))
1896 npar = npar->Next()->NextAfterFootnote();
1898 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1900 p1 = ppar->pextra_width,
1901 p2 = ppar->pextra_widthp;
1902 ppar->SetPExtraType(bparams, ppar->pextra_type,
1903 p1.c_str(), p2.c_str());
1905 if ((par->pextra_type == PEXTRA_NONE) &&
1906 npar && (npar->pextra_type != PEXTRA_NONE)) {
1908 p1 = npar->pextra_width,
1909 p2 = npar->pextra_widthp;
1910 npar->SetPExtraType(bparams, npar->pextra_type,
1911 p1.c_str(), p2.c_str());
1917 // if the layout of a paragraph contains a manual label, the beginning of the
1918 // main body is the beginning of the second word. This is what the par-
1919 // function returns. If the layout does not contain a label, the main
1920 // body always starts with position 0. This differentiation is necessary,
1921 // because there cannot be a newline or a blank <= the beginning of the
1922 // main body in TeX.
1924 int LyXParagraph::BeginningOfMainBody() const
1926 if (FirstPhysicalPar() != this)
1929 // Unroll the first two cycles of the loop
1930 // and remember the previous character to
1931 // remove unnecessary GetChar() calls
1934 && GetChar(i) != LyXParagraph::META_NEWLINE
1937 char previous_char = 0, temp = 0;
1939 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1940 // Yes, this ^ is supposed to be "= " not "=="
1943 && previous_char != ' '
1944 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1946 previous_char = temp;
1951 if (i == 0 && i == size() &&
1952 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1953 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1954 ++i; /* the cursor should not jump
1955 * to the main body if there
1961 LyXParagraph * LyXParagraph::DepthHook(int deth)
1963 LyXParagraph * newpar = this;
1968 newpar = newpar->FirstPhysicalPar()->Previous();
1969 } while (newpar && newpar->GetDepth() > deth
1970 && newpar->footnoteflag == footnoteflag);
1973 if (Previous() || GetDepth())
1974 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1978 return newpar->FirstPhysicalPar();
1982 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1984 LyXParagraph const * newpar = this;
1989 newpar = newpar->FirstPhysicalPar()->Previous();
1990 } while (newpar && newpar->GetDepth() > deth
1991 && newpar->footnoteflag == footnoteflag);
1994 if (Previous() || GetDepth())
1995 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1999 return newpar->FirstPhysicalPar();
2003 int LyXParagraph::AutoDeleteInsets()
2006 InsetList::size_type index = 0;
2007 while (index < insetlist.size()) {
2008 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2009 Erase(insetlist[index].pos);
2010 // Erase() calls to insetlist.erase(&insetlist[index])
2011 // so index shouldn't be increased.
2020 LyXParagraph::inset_iterator
2021 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2023 InsetTable search_inset(pos, 0);
2024 InsetList::iterator it = lower_bound(insetlist.begin(),
2026 search_inset, matchIT());
2027 return inset_iterator(it);
2031 // returns -1 if inset not found
2032 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2035 // We could use lower_bound here too, we just need to add
2036 // the approp. operator() to matchIT (and change the name
2037 // of that struct). Code would then be:
2038 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2040 // inset, matchIT());
2041 // if ((*cit).inset == inset) {
2042 // return (*cit).pos;
2044 for (InsetList::const_iterator cit = insetlist.begin();
2045 cit != insetlist.end(); ++cit) {
2046 if ((*cit).inset == inset) {
2050 // Think about footnotes.
2051 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2052 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2054 NextAfterFootnote()->GetPositionOfInset(inset);
2056 return text.size() + 1 + further;
2062 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2063 BufferParams const & bparams,
2064 ostream & os, TexRow & texrow,
2067 TexRow & foot_texrow,
2070 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2071 LyXLayout const & style =
2072 textclasslist.Style(bparams.textclass,
2075 bool further_blank_line = false;
2077 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2079 if (start_of_appendix) {
2080 os << "\\appendix\n";
2084 if (!spacing.isDefault()
2085 && (!Previous() || !Previous()->HasSameLayout(this))) {
2086 os << spacing.writeEnvirBegin() << "\n";
2090 if (tex_code_break_column && style.isCommand()){
2095 if (pagebreak_top) {
2097 further_blank_line = true;
2099 if (added_space_top.kind() != VSpace::NONE) {
2100 os << added_space_top.asLatexCommand(bparams);
2101 further_blank_line = true;
2105 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2106 << "\\vspace{-1\\parskip}";
2107 further_blank_line = true;
2110 if (further_blank_line){
2115 Language const * language = getParLanguage(bparams);
2116 Language const * doc_language = bparams.language_info;
2117 Language const * previous_language = previous
2118 ? previous->getParLanguage(bparams) : doc_language;
2119 if (language != doc_language && language != previous_language) {
2120 os << subst(lyxrc.language_command_begin, "$$lang",
2126 if (bparams.inputenc == "auto" &&
2127 language->encoding() != previous_language->encoding()) {
2128 os << "\\inputencoding{"
2129 << language->encoding()->LatexName()
2134 switch (style.latextype) {
2137 << style.latexname()
2138 << style.latexparam();
2140 case LATEX_ITEM_ENVIRONMENT:
2142 bibkey->Latex(buf, os, false, false);
2146 case LATEX_LIST_ENVIRONMENT:
2153 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2156 // Spit out footnotes
2157 LyXParagraph * par = next;
2158 if (lyxrc.rtl_support) {
2159 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2160 && next->footnoteflag != footnoteflag) {
2161 LyXParagraph * p = 0;
2162 bool is_rtl = (size() > 0)
2163 ? GetFontSettings(bparams,
2164 size()-1).isRightToLeft()
2165 : language->RightToLeft();
2166 if ( (p = NextAfterFootnote()) != 0 &&
2168 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2169 is_rtl = getParLanguage(bparams)->RightToLeft();
2170 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2171 && par->footnoteflag != footnoteflag) {
2172 par = par->TeXFootnote(buf, bparams,
2174 foot_texrow, foot_count,
2176 par->SimpleTeXOnePar(buf, bparams,
2177 os, texrow, moving_arg);
2178 is_rtl = (par->size() > 0)
2179 ? par->GetFontSettings(bparams,
2180 par->size()-1).isRightToLeft()
2181 : language->RightToLeft();
2183 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2184 (p = par->NextAfterFootnote()) != 0 &&
2186 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2187 is_rtl = language->RightToLeft();
2192 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2193 && par->footnoteflag != footnoteflag) {
2194 par = par->TeXFootnote(buf, bparams,
2196 foot, foot_texrow, foot_count,
2198 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2204 // Make sure that \\par is done with the font of the last
2205 // character if this has another size as the default.
2206 // This is necessary because LaTeX (and LyX on the screen)
2207 // calculates the space between the baselines according
2208 // to this font. (Matthias)
2209 LyXFont font = getFont(bparams, Last() - 1);
2211 if (style.resfont.size() != font.size()) {
2217 } else if (textclasslist.Style(bparams.textclass,
2218 GetLayout()).isCommand()) {
2219 if (style.resfont.size() != font.size()) {
2225 } else if (style.resfont.size() != font.size()){
2226 os << "{\\" << font.latexSize() << " \\par}";
2229 if (language != doc_language &&
2231 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2232 || par->getParLanguage(bparams) != language)) {
2234 << subst(lyxrc.language_command_end, "$$lang",
2235 doc_language->lang());
2238 switch (style.latextype) {
2239 case LATEX_ITEM_ENVIRONMENT:
2240 case LATEX_LIST_ENVIRONMENT:
2241 if (par && (depth < par->depth)) {
2246 case LATEX_ENVIRONMENT:
2247 // if its the last paragraph of the current environment
2248 // skip it otherwise fall through
2250 && (par->layout != layout
2251 || par->depth != depth
2252 || par->pextra_type != pextra_type))
2255 // we don't need it for the last paragraph!!!
2256 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2257 && footnotekind != LyXParagraph::FOOTNOTE
2258 && footnotekind != LyXParagraph::MARGIN
2262 // don't insert this if we would be adding it
2263 // before or after a table in a float. This
2264 // little trick is needed in order to allow
2265 // use of tables in \subfigures or \subtables.
2271 further_blank_line = false;
2273 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2274 further_blank_line = true;
2277 if (added_space_bottom.kind() != VSpace::NONE) {
2278 os << added_space_bottom.asLatexCommand(bparams);
2279 further_blank_line = true;
2282 if (pagebreak_bottom) {
2284 further_blank_line = true;
2287 if (further_blank_line){
2292 if (!spacing.isDefault()
2293 && (!par || !par->HasSameLayout(this))) {
2294 os << spacing.writeEnvirEnd() << "\n";
2298 // we don't need it for the last paragraph!!!
2299 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2300 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2305 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2310 // This one spits out the text of the paragraph
2311 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2312 BufferParams const & bparams,
2313 ostream & os, TexRow & texrow,
2316 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2320 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2323 bool return_value = false;
2325 LyXLayout const & style =
2326 textclasslist.Style(bparams.textclass,
2328 LyXFont basefont, last_font;
2330 // Maybe we have to create a optional argument.
2331 size_type main_body;
2332 if (style.labeltype != LABEL_MANUAL)
2335 main_body = BeginningOfMainBody();
2337 if (main_body > 0) {
2339 basefont = getFont(bparams, -2); // Get label font
2341 basefont = getFont(bparams, -1); // Get layout font
2349 if (style.isCommand()) {
2352 } else if (align != LYX_ALIGN_LAYOUT) {
2355 return_value = true;
2359 moving_arg |= style.needprotect;
2361 // Which font is currently active?
2362 LyXFont running_font(basefont);
2363 // Do we have an open font change?
2364 bool open_font = false;
2366 texrow.start(this, 0);
2368 for (size_type i = 0; i < size(); ++i) {
2370 // First char in paragraph or after label?
2371 if (i == main_body && !IsDummy()) {
2372 if (main_body > 0) {
2374 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2377 basefont = getFont(bparams, -1); // Now use the layout font
2378 running_font = basefont;
2382 if (style.isCommand()) {
2385 } else if (align != LYX_ALIGN_LAYOUT) {
2388 return_value = true;
2392 os << "\\noindent ";
2396 case LYX_ALIGN_NONE:
2397 case LYX_ALIGN_BLOCK:
2398 case LYX_ALIGN_LAYOUT:
2399 case LYX_ALIGN_SPECIAL:
2401 case LYX_ALIGN_LEFT:
2402 if (getParLanguage(bparams)->lang() != "hebrew") {
2403 os << "\\raggedright ";
2406 os << "\\raggedleft ";
2410 case LYX_ALIGN_RIGHT:
2411 if (getParLanguage(bparams)->lang() != "hebrew") {
2412 os << "\\raggedleft ";
2415 os << "\\raggedright ";
2419 case LYX_ALIGN_CENTER:
2420 os << "\\centering ";
2426 value_type c = GetChar(i);
2428 // Fully instantiated font
2429 LyXFont font = getFont(bparams, i);
2430 LyXParagraph * p = 0;
2431 if (i == 0 && previous &&
2432 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2433 (p = PreviousBeforeFootnote()) != 0)
2434 last_font = p->getFont(bparams, p->size()-1);
2436 last_font = running_font;
2438 // Spaces at end of font change are simulated to be
2439 // outside font change, i.e. we write "\textXX{text} "
2440 // rather than "\textXX{text }". (Asger)
2441 if (open_font && c == ' ' && i <= size() - 2
2442 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2443 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2444 font = getFont(bparams, i + 1);
2446 // We end font definition before blanks
2447 if (!font.equalExceptLatex(running_font) && open_font) {
2448 column += running_font.latexWriteEndChanges(os,
2450 (i == main_body-1) ? basefont : font);
2451 running_font = basefont;
2455 // Blanks are printed before start of fontswitch
2457 // Do not print the separation of the optional argument
2458 if (i != main_body - 1) {
2459 SimpleTeXBlanks(os, texrow, i,
2460 column, font, style);
2464 // Do we need to change font?
2465 if (!font.equalExceptLatex(running_font)
2466 && i != main_body-1) {
2467 column += font.latexWriteStartChanges(os, basefont,
2469 running_font = font;
2473 if (c == LyXParagraph::META_NEWLINE) {
2474 // newlines are handled differently here than
2475 // the default in SimpleTeXSpecialChars().
2476 if (!style.newline_allowed
2477 || font.latex() == LyXFont::ON) {
2481 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2484 basefont = getFont(bparams, -1);
2485 running_font = basefont;
2486 if (font.family() ==
2487 LyXFont::TYPEWRITER_FAMILY) {
2495 texrow.start(this, i + 1);
2498 SimpleTeXSpecialChars(buf, bparams,
2499 os, texrow, moving_arg,
2500 font, running_font, basefont,
2501 open_font, style, i, column, c);
2505 // If we have an open font definition, we have to close it
2507 LyXParagraph * p = 0;
2508 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2509 && (p = NextAfterFootnote()) != 0)
2510 running_font.latexWriteEndChanges(os, basefont,
2511 p->getFont(bparams, 0));
2513 running_font.latexWriteEndChanges(os, basefont, basefont);
2516 // Needed if there is an optional argument but no contents.
2517 if (main_body > 0 && main_body == size()) {
2519 return_value = false;
2522 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2523 return return_value;
2527 // This one spits out the text of a table paragraph
2528 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2529 BufferParams const & bparams,
2530 ostream & os, TexRow & texrow)
2532 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2534 bool return_value = false;
2536 LyXLayout const & style =
2537 textclasslist.Style(bparams.textclass, GetLayout());
2540 if (!IsDummy()) { // it is dummy if it is in a float!!!
2541 if (style.isCommand()) {
2544 } else if (align != LYX_ALIGN_LAYOUT) {
2547 return_value = true;
2550 os << "\\noindent ";
2554 case LYX_ALIGN_NONE:
2555 case LYX_ALIGN_BLOCK:
2556 case LYX_ALIGN_LAYOUT:
2557 case LYX_ALIGN_SPECIAL: break;
2558 case LYX_ALIGN_LEFT:
2559 os << "\\raggedright ";
2562 case LYX_ALIGN_RIGHT:
2563 os << "\\raggedleft ";
2566 case LYX_ALIGN_CENTER:
2567 os << "\\centering ";
2573 LyXFont basefont = getFont(bparams, -1); // Get layout font
2574 // Which font is currently active?
2575 LyXFont running_font = basefont;
2577 // Do we have an open font change?
2578 bool open_font = false;
2579 int current_cell_number = -1;
2580 int tmp = table->TexEndOfCell(os, current_cell_number);
2581 for (; tmp > 0 ; --tmp)
2584 texrow.start(this, 0);
2586 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2587 bool first_in_cell = true;
2589 for (size_type i = 0; i < size(); ++i) {
2590 value_type c = GetChar(i);
2591 if (table->IsContRow(current_cell_number + 1)) {
2592 if (c == LyXParagraph::META_NEWLINE)
2593 ++current_cell_number;
2598 if (first_in_cell && is_rtl) {
2601 first_in_cell = false;
2604 // Fully instantiated font
2605 LyXFont font = getFont(bparams, i);
2606 last_font = running_font;
2608 // Spaces at end of font change are simulated to be
2609 // outside font change.
2610 // i.e. we write "\textXX{text} " rather than
2611 // "\textXX{text }". (Asger)
2612 if (open_font && c == ' ' && i <= size() - 2
2613 && getFont(bparams, i + 1) != running_font
2614 && getFont(bparams, i + 1) != font) {
2615 font = getFont(bparams, i + 1);
2618 // We end font definition before blanks
2619 if (font != running_font && open_font) {
2620 column += running_font.latexWriteEndChanges(os,
2623 running_font = basefont;
2626 // Blanks are printed before start of fontswitch
2628 SimpleTeXBlanks(os, texrow, i, column, font, style);
2630 // Do we need to change font?
2631 if (font != running_font) {
2632 column += font.latexWriteStartChanges(os, basefont,
2634 running_font = font;
2637 // Do we need to turn on LaTeX mode?
2638 if (font.latex() != running_font.latex()) {
2639 if (font.latex() == LyXFont::ON
2640 && style.needprotect) {
2645 if (c == LyXParagraph::META_NEWLINE) {
2646 // special case for inside a table
2647 // different from default case in
2648 // SimpleTeXSpecialChars()
2650 column += running_font
2651 .latexWriteEndChanges(os, basefont,
2655 basefont = getFont(bparams, -1);
2656 running_font = basefont;
2657 ++current_cell_number;
2658 if (table->CellHasContRow(current_cell_number) >= 0) {
2659 TeXContTableRows(buf, bparams, os, i + 1,
2660 current_cell_number,
2663 if (is_rtl && !first_in_cell) {
2665 first_in_cell = true;
2668 // if this cell follow only ContRows till end don't
2669 // put the EndOfCell because it is put after the
2671 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2672 --current_cell_number;
2675 int tmp = table->TexEndOfCell(os,
2676 current_cell_number);
2679 } else if (tmp < 0) {
2685 texrow.start(this, i + 1);
2687 SimpleTeXSpecialChars(buf, bparams,
2689 font, running_font, basefont,
2690 open_font, style, i, column, c);
2694 // If we have an open font definition, we have to close it
2696 running_font.latexWriteEndChanges(os, basefont, basefont);
2698 ++current_cell_number;
2699 if (is_rtl && !first_in_cell)
2701 tmp = table->TexEndOfCell(os, current_cell_number);
2702 for (; tmp > 0; --tmp)
2704 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2705 return return_value;
2709 // This one spits out the text off ContRows in tables
2710 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2711 BufferParams const & bparams,
2713 LyXParagraph::size_type i,
2714 int current_cell_number,
2715 int & column, TexRow & texrow)
2717 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2721 bool return_value = false;
2722 LyXLayout const & style =
2723 textclasslist.Style(bparams.textclass,
2725 LyXFont basefont = getFont(bparams, -1); // Get layout font
2727 // Which font is currently active?
2728 LyXFont running_font = basefont;
2729 // Do we have an open font change?
2730 bool open_font = false;
2732 size_type lastpos = i;
2733 int cell = table->CellHasContRow(current_cell_number);
2734 ++current_cell_number;
2737 // first find the right position
2739 for (; (i < size()) && (current_cell_number < cell); ++i) {
2741 if (c == LyXParagraph::META_NEWLINE)
2742 ++current_cell_number;
2746 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2750 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2755 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2759 // Fully instantiated font
2760 LyXFont font = getFont(bparams, i);
2761 last_font = running_font;
2763 // Spaces at end of font change are simulated to
2764 // be outside font change. i.e. we write
2765 // "\textXX{text} " rather than "\textXX{text }".
2767 if (open_font && c == ' ' && i <= size() - 2
2768 && getFont(bparams, i + 1) != running_font
2769 && getFont(bparams, i + 1) != font) {
2770 font = getFont(bparams, i + 1);
2773 // We end font definition before blanks
2774 if (font != running_font && open_font) {
2775 column += running_font.latexWriteEndChanges(os, basefont, font);
2776 running_font = basefont;
2779 // Blanks are printed before start of fontswitch
2781 SimpleTeXBlanks(os, texrow, i,
2782 column, font, style);
2784 // Do we need to change font?
2785 if (font != running_font) {
2787 font.latexWriteStartChanges(os,
2790 running_font = font;
2793 // Do we need to turn on LaTeX mode?
2794 if (font.latex() != running_font.latex()) {
2795 if (font.latex() == LyXFont::ON
2796 && style.needprotect) {
2801 SimpleTeXSpecialChars(buf, bparams,
2802 os, texrow, false, font,
2803 running_font, basefont,
2804 open_font, style, i, column, c);
2806 // If we have an open font definition, we have to close it
2808 running_font.latexWriteEndChanges(os, basefont,
2812 basefont = getFont(bparams, -1);
2813 running_font = basefont;
2814 cell = table->CellHasContRow(current_cell_number);
2816 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2817 return return_value;
2821 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2823 bool retval = false;
2825 case LyXParagraph::META_HFILL:
2826 sgml_string.erase();
2828 case LyXParagraph::META_NEWLINE:
2832 sgml_string = "&";
2835 sgml_string = "<";
2838 sgml_string = ">";
2841 sgml_string = "$";
2844 sgml_string = "#";
2847 sgml_string = "%";
2850 sgml_string = "[";
2853 sgml_string = "]";
2856 sgml_string = "{";
2859 sgml_string = "}";
2862 sgml_string = "˜";
2865 sgml_string = """;
2868 sgml_string = "\";
2874 case '\0': // Ignore :-)
2875 sgml_string.erase();
2885 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
2886 ostream & os, string & extra,
2887 int & desc_on, int depth)
2889 BufferParams const & bparams = buffer->params;
2891 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2893 LyXFont font1, font2;
2896 size_type main_body;
2897 bool emph_flag = false;
2899 LyXLayout const & style =
2900 textclasslist.Style(bparams.textclass,
2903 if (style.labeltype != LABEL_MANUAL)
2906 main_body = BeginningOfMainBody();
2908 // Gets paragraph main font.
2910 font1 = style.labelfont;
2914 int char_line_count = depth;
2915 os << newlineAndDepth(depth);
2916 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2917 os << "<INFORMALTABLE>"
2918 << newlineAndDepth(++depth);
2920 int current_cell_number = -1;
2921 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2923 // Parsing main loop.
2924 for (size_type i = 0; i < size(); ++i) {
2926 if (table->IsContRow(current_cell_number+1)) {
2927 if (c == LyXParagraph::META_NEWLINE)
2928 ++current_cell_number;
2933 // Fully instantiated font
2934 font2 = getFont(bparams, i);
2936 // Handle <emphasis> tag.
2937 if (font1.emph() != font2.emph() && i) {
2938 if (font2.emph() == LyXFont::ON) {
2941 } else if (emph_flag) {
2942 os << "</emphasis>";
2946 if (c == LyXParagraph::META_NEWLINE) {
2947 // We have only to control for emphasis open here!
2949 os << "</emphasis>";
2952 font1 = font2 = getFont(bparams, -1);
2953 ++current_cell_number;
2954 if (table->CellHasContRow(current_cell_number) >= 0) {
2955 DocBookContTableRows(buffer,
2956 os, extra, desc_on, i + 1,
2957 current_cell_number,
2960 // if this cell follow only ContRows till end don't
2961 // put the EndOfCell because it is put after the
2963 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2964 --current_cell_number;
2967 tmp = table->DocBookEndOfCell(os,
2968 current_cell_number,
2973 } else if (c == LyXParagraph::META_INSET) {
2974 inset = GetInset(i);
2976 std::ostringstream ost;
2977 inset->DocBook(buffer, ost);
2978 string tmp_out = ost.str().c_str();
2981 inset->DocBook(buffer, ost);
2983 char * ctmp = ost.str();
2984 string tmp_out(ctmp);
2988 // This code needs some explanation:
2989 // Two insets are treated specially
2990 // label if it is the first element in a
2991 // command paragraph
2993 // graphics inside tables or figure floats
2995 // title (the equivalente in latex for this
2997 // and title should come first
3000 if(desc_on != 3 || i != 0) {
3001 if(tmp_out[0] == '@') {
3003 extra += frontStrip(tmp_out,
3006 os << frontStrip(tmp_out,
3011 } else if (font2.latex() == LyXFont::ON) {
3012 // "TeX"-Mode on == > SGML-Mode on.
3018 if (linuxDocConvertChar(c, sgml_string)
3019 && !style.free_spacing) {
3020 // in freespacing mode, spaces are
3021 // non-breaking characters
3026 << "</term><listitem><para>";
3038 // Needed if there is an optional argument but no contents.
3039 if (main_body > 0 && main_body == size()) {
3044 os << "</emphasis>";
3047 ++current_cell_number;
3048 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3049 // Resets description flag correctly.
3052 // <term> not closed...
3056 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3057 os << "</INFORMALTABLE>";
3059 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3064 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3065 ostream & os, string & extra,
3067 LyXParagraph::size_type i,
3068 int current_cell_number, int &column)
3073 BufferParams const & bparams = buffer->params;
3075 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3080 //string emph = "emphasis";
3081 bool emph_flag = false;
3082 int char_line_count = 0;
3084 LyXLayout const & style =
3085 textclasslist.Style(bparams.textclass,
3088 size_type main_body;
3089 if (style.labeltype != LABEL_MANUAL)
3092 main_body = BeginningOfMainBody();
3094 // Gets paragraph main font.
3097 font1 = style.labelfont;
3101 size_type lastpos = i;
3102 int cell = table->CellHasContRow(current_cell_number);
3103 ++current_cell_number;
3105 // first find the right position
3107 for (; i < size() && current_cell_number < cell; ++i) {
3109 if (c == LyXParagraph::META_NEWLINE)
3110 ++current_cell_number;
3114 // I don't know how to handle this so I comment it
3115 // for the moment (Jug)
3116 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3117 // file += " \\\\\n";
3120 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3125 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3129 // Fully instantiated font
3130 font2 = getFont(bparams, i);
3132 // Handle <emphasis> tag.
3133 if (font1.emph() != font2.emph() && i) {
3134 if (font2.emph() == LyXFont::ON) {
3137 } else if (emph_flag) {
3138 os << "</emphasis>";
3142 if (c == LyXParagraph::META_INSET) {
3143 inset = GetInset(i);
3145 std::ostringstream ost;
3146 inset->DocBook(buffer, ost);
3147 string tmp_out = ost.str().c_str();
3150 inset->DocBook(buffer, ost);
3152 char * ctmp = ost.str();
3153 string tmp_out(ctmp);
3157 // This code needs some explanation:
3158 // Two insets are treated specially
3159 // label if it is the first element in a
3160 // command paragraph
3162 // graphics inside tables or figure floats
3163 // can't go on title (the equivalente in
3164 // latex for this case is caption and title
3165 // should come first
3168 if(desc_on != 3 || i != 0) {
3169 if(tmp_out[0] == '@') {
3171 extra += frontStrip(tmp_out, '@');
3173 os << frontStrip(tmp_out, '@');
3177 } else if (font2.latex() == LyXFont::ON) {
3178 // "TeX"-Mode on == > SGML-Mode on.
3184 if (linuxDocConvertChar(c, sgml_string)
3185 && !style.free_spacing) {
3186 // in freespacing mode, spaces are
3187 // non-breaking characters
3192 << "</term><listitem><para>";
3202 // we have only to control for emphasis open here!
3204 os << "</emphasis>";
3207 font1 = font2 = getFont(bparams, -1);
3208 cell = table->CellHasContRow(current_cell_number);
3210 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3214 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3215 LyXParagraph::size_type const i,
3216 int & column, LyXFont const & font,
3217 LyXLayout const & style)
3219 if (column > tex_code_break_column
3221 && GetChar(i - 1) != ' '
3223 // In LaTeX mode, we don't want to
3224 // break lines since some commands
3226 && ! (font.latex() == LyXFont::ON)
3227 // same in FreeSpacing mode
3228 && !style.free_spacing
3229 // In typewriter mode, we want to avoid
3230 // ! . ? : at the end of a line
3231 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3232 && (GetChar(i-1) == '.'
3233 || GetChar(i-1) == '?'
3234 || GetChar(i-1) == ':'
3235 || GetChar(i-1) == '!'))) {
3236 if (tex_code_break_column == 0) {
3237 // in batchmode we need LaTeX to still
3238 // see it as a space not as an extra '\n'
3244 texrow.start(this, i + 1);
3246 } else if (font.latex() == LyXFont::OFF) {
3247 if (style.free_spacing) {
3256 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3257 BufferParams const & bparams,
3258 ostream & os, TexRow & texrow,
3261 LyXFont & running_font,
3264 LyXLayout const & style,
3265 LyXParagraph::size_type & i,
3267 LyXParagraph::value_type const c)
3269 // Two major modes: LaTeX or plain
3270 // Handle here those cases common to both modes
3271 // and then split to handle the two modes separately.
3273 case LyXParagraph::META_INSET: {
3274 Inset * inset = GetInset(i);
3277 int len = os.tellp();
3278 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3279 || inset->LyxCode() == Inset::MATH_CODE
3280 || inset->LyxCode() == Inset::URL_CODE)
3281 && running_font.isRightToLeft()) {
3286 int tmp = inset->Latex(buf, os, moving_arg,
3287 style.free_spacing);
3295 column += os.tellp() - len;
3304 case LyXParagraph::META_NEWLINE:
3306 column += running_font.latexWriteEndChanges(os,
3311 basefont = getFont(bparams, -1);
3312 running_font = basefont;
3315 case LyXParagraph::META_HFILL:
3321 // And now for the special cases within each mode
3322 // Are we in LaTeX mode?
3323 if (font.latex() == LyXFont::ON) {
3324 // at present we only have one option
3325 // but I'll leave it as a switch statement
3326 // so its simpler to extend. (ARRae)
3329 // make sure that we will not print
3330 // error generating chars to the tex
3331 // file. This test would not be needed
3332 // if it were done in the buffer
3340 // Plain mode (i.e. not LaTeX)
3343 os << "\\textbackslash{}";
3347 case '°': case '±': case '²': case '³':
3348 case '×': case '÷': case '¹': case 'ª':
3349 case 'º': case '¬': case 'µ':
3350 if (bparams.inputenc == "latin1" ||
3351 (bparams.inputenc == "auto" &&
3352 font.language()->encoding()->LatexName()
3354 os << "\\ensuremath{"
3363 case '|': case '<': case '>':
3364 // In T1 encoding, these characters exist
3365 if (lyxrc.fontenc == "T1") {
3367 //... but we should avoid ligatures
3368 if ((c == '>' || c == '<')
3370 && GetChar(i + 1) == c) {
3371 //os << "\\textcompwordmark{}";
3372 // Jean-Marc, have a look at
3373 // this. IÂ think this works
3381 // Typewriter font also has them
3382 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3386 // Otherwise, we use what LaTeX
3390 os << "\\textless{}";
3394 os << "\\textgreater{}";
3398 os << "\\textbar{}";
3404 case '-': // "--" in Typewriter mode -> "-{}-"
3406 && GetChar(i + 1) == '-'
3407 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3416 os << "\\char`\\\"{}";
3421 if (bparams.inputenc == "default") {
3430 case '%': case '#': case '{':
3437 os << "\\textasciitilde{}";
3442 os << "\\textasciicircum{}";
3446 case '*': case '[': case ']':
3447 // avoid being mistaken for optional arguments
3448 os << '{' << c << '}';
3453 // Blanks are printed before font switching.
3454 // Sure? I am not! (try nice-latex)
3455 // I am sure it's correct. LyX might be smarter
3456 // in the future, but for now, nothing wrong is
3461 /* idea for labels --- begin*/
3465 && font.family() != LyXFont::TYPEWRITER_FAMILY
3466 && GetChar(i + 1) == 'y'
3467 && GetChar(i + 2) == 'X') {
3475 && font.family() != LyXFont::TYPEWRITER_FAMILY
3476 && GetChar(i + 1) == 'e'
3477 && GetChar(i + 2) == 'X') {
3482 // Check for "LaTeX2e"
3485 && font.family() != LyXFont::TYPEWRITER_FAMILY
3486 && GetChar(i + 1) == 'a'
3487 && GetChar(i + 2) == 'T'
3488 && GetChar(i + 3) == 'e'
3489 && GetChar(i + 4) == 'X'
3490 && GetChar(i + 5) == '2'
3491 && GetChar(i + 6) == 'e') {
3496 // Check for "LaTeX"
3499 && font.family() != LyXFont::TYPEWRITER_FAMILY
3500 && GetChar(i + 1) == 'a'
3501 && GetChar(i + 2) == 'T'
3502 && GetChar(i + 3) == 'e'
3503 && GetChar(i + 4) == 'X') {
3507 /* idea for labels --- end*/
3508 } else if (c != '\0') {
3518 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3519 BufferParams const & bparams,
3520 ostream & os, TexRow & texrow,
3522 TexRow & foot_texrow,
3525 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3526 LyXParagraph * par = this;
3529 (par->depth == depth) &&
3530 (par->footnoteflag == footnoteflag)) {
3532 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3533 if (textclasslist.Style(bparams.textclass,
3534 par->layout).isEnvironment()
3535 || par->pextra_type != PEXTRA_NONE) {
3536 par = par->TeXEnvironment(buf, bparams,
3541 par = par->TeXOnePar(buf, bparams,
3547 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3553 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3554 BufferParams const & bparams,
3555 ostream & os, TexRow & texrow,
3557 TexRow & foot_texrow,
3560 bool eindent_open = false;
3561 bool foot_this_level = false;
3562 // flags when footnotetext should be appended to file.
3563 static bool minipage_open = false;
3564 static int minipage_open_depth = 0;
3565 char par_sep = bparams.paragraph_separation;
3567 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3569 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3571 LyXLayout const & style =
3572 textclasslist.Style(bparams.textclass,
3575 if (pextra_type == PEXTRA_INDENT) {
3576 if (!pextra_width.empty()) {
3577 os << "\\begin{LyXParagraphIndent}{"
3578 << pextra_width << "}\n";
3580 //float ib = atof(pextra_widthp.c_str())/100;
3581 // string can't handle floats at present (971109)
3582 // so I'll do a conversion by hand knowing that
3583 // the limits are 0.0 to 1.0. ARRae.
3584 os << "\\begin{LyXParagraphIndent}{";
3585 switch (pextra_widthp.length()) {
3597 os << "\\columnwidth}\n";
3600 eindent_open = true;
3602 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3603 if (pextra_hfill && Previous() &&
3604 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3605 os << "\\hfill{}\n";
3608 if (par_sep == BufferParams::PARSEP_INDENT) {
3609 os << "{\\setlength\\parindent{0pt}\n";
3612 os << "\\begin{minipage}";
3613 switch(pextra_alignment) {
3614 case MINIPAGE_ALIGN_TOP:
3617 case MINIPAGE_ALIGN_MIDDLE:
3620 case MINIPAGE_ALIGN_BOTTOM:
3624 if (!pextra_width.empty()) {
3625 os << '{' << pextra_width << "}\n";
3627 //float ib = atof(par->pextra_width.c_str())/100;
3628 // string can't handle floats at present
3629 // so I'll do a conversion by hand knowing that
3630 // the limits are 0.0 to 1.0. ARRae.
3632 switch (pextra_widthp.length()) {
3644 os << "\\columnwidth}\n";
3647 if (par_sep == BufferParams::PARSEP_INDENT) {
3648 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3651 minipage_open = true;
3652 minipage_open_depth = depth;
3655 #ifdef WITH_WARNINGS
3656 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3657 //I disabled it because it breaks when lists span on several
3660 if (style.isEnvironment()){
3661 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3662 #ifdef FANCY_FOOTNOTE_CODE
3663 if (foot_count < 0) {
3664 // flag that footnote[mark][text] should be
3665 // used for any footnotes from now on
3667 foot_this_level = true;
3670 os << "\\begin{" << style.latexname() << "}{"
3671 << labelwidthstring << "}\n";
3672 } else if (style.labeltype == LABEL_BIBLIO) {
3674 os << "\\begin{" << style.latexname() << "}{"
3675 << bibitemWidest(current_view)
3677 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3678 #ifdef FANCY_FOOTNOTE_CODE
3679 if (foot_count < 0) {
3680 // flag that footnote[mark][text] should be
3681 // used for any footnotes from now on
3683 foot_this_level = true;
3686 os << "\\begin{" << style.latexname() << '}'
3687 << style.latexparam() << '\n';
3689 os << "\\begin{" << style.latexname() << '}'
3690 << style.latexparam() << '\n';
3693 LyXParagraph * par = this;
3695 par = par->TeXOnePar(buf, bparams,
3697 foot, foot_texrow, foot_count);
3699 if (minipage_open && par && !style.isEnvironment() &&
3700 (par->pextra_type == PEXTRA_MINIPAGE) &&
3701 par->pextra_start_minipage) {
3702 os << "\\end{minipage}\n";
3704 if (par_sep == BufferParams::PARSEP_INDENT) {
3708 minipage_open = false;
3710 if (par && par->depth > depth) {
3711 if (textclasslist.Style(bparams.textclass,
3712 par->layout).isParagraph()
3715 // How to handle this? (Lgb)
3716 //&& !suffixIs(os, "\n\n")
3718 // There should be at least one '\n' already
3719 // but we need there to be two for Standard
3720 // paragraphs that are depth-increment'ed to be
3721 // output correctly. However, tables can
3722 // also be paragraphs so don't adjust them.
3725 // Will it ever harm to have one '\n' too
3726 // many? i.e. that we sometimes will have
3727 // three in a row. (Lgb)
3731 par = par->TeXDeeper(buf, bparams, os, texrow,
3732 foot, foot_texrow, foot_count);
3734 if (par && par->layout == layout && par->depth == depth &&
3735 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3736 if (par->pextra_hfill && par->Previous() &&
3737 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3738 os << "\\hfill{}\n";
3741 if (par_sep == BufferParams::PARSEP_INDENT) {
3742 os << "{\\setlength\\parindent{0pt}\n";
3745 os << "\\begin{minipage}";
3746 switch(par->pextra_alignment) {
3747 case MINIPAGE_ALIGN_TOP:
3750 case MINIPAGE_ALIGN_MIDDLE:
3753 case MINIPAGE_ALIGN_BOTTOM:
3757 if (!par->pextra_width.empty()) {
3758 os << '{' << par->pextra_width << "}\n";
3760 //float ib = atof(par->pextra_widthp.c_str())/100;
3761 // string can't handle floats at present
3762 // so I'll do a conversion by hand knowing that
3763 // the limits are 0.0 to 1.0. ARRae.
3765 switch (par->pextra_widthp.length()) {
3770 os << "0." << par->pextra_widthp;
3773 os << "0.0" << par->pextra_widthp;
3775 os << "\\columnwidth}\n";
3778 if (par_sep == BufferParams::PARSEP_INDENT) {
3779 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3782 minipage_open = true;
3783 minipage_open_depth = par->depth;
3786 && par->layout == layout
3787 && par->depth == depth
3788 && par->pextra_type == pextra_type
3789 && par->footnoteflag == footnoteflag);
3791 if (style.isEnvironment()) {
3792 os << "\\end{" << style.latexname() << '}';
3793 // maybe this should go after the minipage closes?
3794 if (foot_this_level) {
3795 if (foot_count >= 1) {
3796 if (foot_count > 1) {
3797 os << "\\addtocounter{footnote}{-"
3802 texrow += foot_texrow;
3804 foot_texrow.reset();
3809 if (minipage_open && (minipage_open_depth == depth) &&
3810 (!par || par->pextra_start_minipage ||
3811 par->pextra_type != PEXTRA_MINIPAGE)) {
3812 os << "\\end{minipage}\n";
3814 if (par_sep == BufferParams::PARSEP_INDENT) {
3818 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3819 os << "\\medskip\n\n";
3823 minipage_open = false;
3826 os << "\\end{LyXParagraphIndent}\n";
3829 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3830 && par->pextra_hfill)) {
3834 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3835 return par; // ale970302
3840 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3841 BufferParams const & bparams,
3842 ostream & os, TexRow & texrow,
3843 ostream & foot, TexRow & foot_texrow,
3847 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3848 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3849 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3850 "No footnote!" << endl;
3852 LyXParagraph * par = this;
3853 LyXLayout const & style =
3854 textclasslist.Style(bparams.textclass,
3855 previous->GetLayout());
3857 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3858 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3859 "Float other than footnote in command"
3860 " with moving argument is illegal" << endl;
3863 if (footnotekind != LyXParagraph::FOOTNOTE
3864 && footnotekind != LyXParagraph::MARGIN
3867 // How to solve this?
3868 //&& !suffixIs(file, '\n')
3870 // we need to ensure that real floats like tables and figures
3871 // have their \begin{} on a new line otherwise we can get
3872 // incorrect results when using the endfloat.sty package
3873 // especially if two floats follow one another. ARRae 981022
3874 // NOTE: if the file is length 0 it must have just been
3875 // written out so we assume it ended with a '\n'
3877 // As far as I can see there is never any harm in writing
3878 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3883 bool moving_arg = false;
3884 bool need_closing = false;
3885 bool is_rtl = isRightToLeftPar(bparams);
3887 if (is_rtl != parent_is_rtl) {
3892 need_closing = true;
3895 //BufferParams * params = ¤t_view->buffer()->params;
3896 bool footer_in_body = true;
3897 switch (footnotekind) {
3898 case LyXParagraph::FOOTNOTE:
3899 if (style.intitle) {
3900 os << "\\thanks{\n";
3901 footer_in_body = false;
3904 if (foot_count == -1) {
3905 // we're at depth 0 so we can use:
3906 os << "\\footnote{%\n";
3907 footer_in_body = false;
3909 os << "\\footnotemark{}%\n";
3911 // we only need this when there are
3912 // multiple footnotes
3913 os << "\\stepcounter{footnote}";
3915 os << "\\footnotetext{%\n";
3916 foot_texrow.start(this, 0);
3917 foot_texrow.newline();
3922 case LyXParagraph::MARGIN:
3923 os << "\\marginpar{\n";
3925 case LyXParagraph::FIG:
3926 if (pextra_type == PEXTRA_FLOATFLT
3927 && (!pextra_width.empty()
3928 || !pextra_widthp.empty())) {
3929 if (!pextra_width.empty())
3930 os << "\\begin{floatingfigure}{"
3931 << pextra_width << "}\n";
3933 os << "\\begin{floatingfigure}{"
3934 << atoi(pextra_widthp.c_str())/100.0
3935 << "\\textwidth}\n";
3937 os << "\\begin{figure}";
3938 if (!bparams.float_placement.empty()) {
3939 os << '[' << bparams.float_placement << "]\n";
3945 case LyXParagraph::TAB:
3946 os << "\\begin{table}";
3947 if (!bparams.float_placement.empty()) {
3948 os << '[' << bparams.float_placement << "]\n";
3953 case LyXParagraph::WIDE_FIG:
3954 os << "\\begin{figure*}";
3955 if (!bparams.float_placement.empty()) {
3956 os << '[' << bparams.float_placement << "]\n";
3961 case LyXParagraph::WIDE_TAB:
3962 os << "\\begin{table*}";
3963 if (!bparams.float_placement.empty()) {
3964 os << '[' << bparams.float_placement << "]\n";
3969 case LyXParagraph::ALGORITHM:
3970 os << "\\begin{algorithm}\n";
3975 if (footnotekind != LyXParagraph::FOOTNOTE
3976 || !footer_in_body) {
3977 // Process text for all floats except footnotes in body
3979 LyXLayout const & style =
3981 .Style(bparams.textclass, par->layout);
3983 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3985 if (style.isEnvironment()
3986 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3987 // Allows the use of minipages within float
3988 // environments. Shouldn't be circular because
3989 // we don't support footnotes inside
3990 // floats (yet). ARRae
3991 par = par->TeXEnvironment(buf, bparams, os,
3996 par = par->TeXOnePar(buf, bparams,
3997 os, texrow, moving_arg,
4002 if (par && !par->IsDummy() && par->depth > depth) {
4003 par = par->TeXDeeper(buf, bparams, os, texrow,
4007 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4009 // process footnotes > depth 0 or in environments separately
4010 // NOTE: Currently don't support footnotes within footnotes
4011 // even though that is possible using the \footnotemark
4013 std::ostringstream dummy;
4017 TexRow dummy_texrow;
4018 int dummy_count = 0;
4020 LyXLayout const & style =
4022 .Style(bparams.textclass, par->layout);
4024 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4026 if (style.isEnvironment()
4027 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4028 // Allows the use of minipages within float
4029 // environments. Shouldn't be circular because
4030 // we don't support footnotes inside
4031 // floats (yet). ARRae
4032 par = par->TeXEnvironment(buf, bparams,
4034 dummy, dummy_texrow,
4037 par = par->TeXOnePar(buf, bparams,
4040 dummy, dummy_texrow,
4044 if (par && !par->IsDummy() && par->depth > depth) {
4045 par = par->TeXDeeper(buf, bparams,
4047 dummy, dummy_texrow,
4051 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4053 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4054 "Footnote in a Footnote -- not supported"
4057 #ifndef HAVE_OSTREAM
4058 delete [] dummy.str();
4062 switch (footnotekind) {
4063 case LyXParagraph::FOOTNOTE:
4064 if (footer_in_body) {
4065 // This helps tell which of the multiple
4066 // footnotetexts an error was in.
4068 foot_texrow.newline();
4073 case LyXParagraph::MARGIN:
4076 case LyXParagraph::FIG:
4077 if (pextra_type == PEXTRA_FLOATFLT
4078 && (!pextra_width.empty()
4079 || !pextra_widthp.empty()))
4080 os << "\\end{floatingfigure}";
4082 os << "\\end{figure}";
4084 case LyXParagraph::TAB:
4085 os << "\\end{table}";
4087 case LyXParagraph::WIDE_FIG:
4088 os << "\\end{figure*}";
4090 case LyXParagraph::WIDE_TAB:
4091 os << "\\end{table*}";
4093 case LyXParagraph::ALGORITHM:
4094 os << "\\end{algorithm}";
4101 if (footnotekind != LyXParagraph::FOOTNOTE
4102 && footnotekind != LyXParagraph::MARGIN) {
4103 // we need to ensure that real floats like tables and figures
4104 // have their \end{} on a line of their own otherwise we can
4105 // get incorrect results when using the endfloat.sty package.
4110 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4115 bool LyXParagraph::IsDummy() const
4117 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4118 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4122 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4123 int type, char const * width,
4124 char const * widthp)
4127 pextra_width = width;
4128 pextra_widthp = widthp;
4130 if (textclasslist.Style(bparams.textclass,
4131 layout).isEnvironment()) {
4136 while (par && (par->layout == layout)
4137 && (par->depth == depth)) {
4139 par = par->Previous();
4141 par = par->FirstPhysicalPar();
4142 while (par && par->depth > depth) {
4143 par = par->Previous();
4145 par = par->FirstPhysicalPar();
4149 while (par && (par->layout == layout)
4150 && (par->depth == depth)) {
4151 par->pextra_type = type;
4152 par->pextra_width = width;
4153 par->pextra_widthp = widthp;
4154 par = par->NextAfterFootnote();
4155 if (par && (par->depth > depth))
4156 par->SetPExtraType(bparams,
4157 type, width, widthp);
4158 while (par && ((par->depth > depth) || par->IsDummy()))
4159 par = par->NextAfterFootnote();
4165 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4167 if (pextra_type == PEXTRA_NONE)
4170 pextra_type = PEXTRA_NONE;
4171 pextra_width.erase();
4172 pextra_widthp.erase();
4174 if (textclasslist.Style(bparams.textclass,
4175 layout).isEnvironment()) {
4180 while (par && (par->layout == layout)
4181 && (par->depth == depth)) {
4183 par = par->Previous();
4185 par = par->FirstPhysicalPar();
4186 while (par && par->depth > depth) {
4187 par = par->Previous();
4189 par = par->FirstPhysicalPar();
4193 while (par && (par->layout == layout)
4194 && (par->depth == depth)) {
4195 par->pextra_type = PEXTRA_NONE;
4196 par->pextra_width.erase();
4197 par->pextra_widthp.erase();
4198 par = par->NextAfterFootnote();
4199 if (par && (par->depth > depth))
4200 par->UnsetPExtraType(bparams);
4201 while (par && ((par->depth > depth) || par->IsDummy()))
4202 par = par->NextAfterFootnote();
4208 bool LyXParagraph::IsHfill(size_type pos) const
4210 return IsHfillChar(GetChar(pos));
4214 bool LyXParagraph::IsInset(size_type pos) const
4216 return IsInsetChar(GetChar(pos));
4220 bool LyXParagraph::IsFloat(size_type pos) const
4222 return IsFloatChar(GetChar(pos));
4226 bool LyXParagraph::IsNewline(size_type pos) const
4228 return pos >= 0 && IsNewlineChar(GetChar(pos));
4232 bool LyXParagraph::IsSeparator(size_type pos) const
4234 return IsSeparatorChar(GetChar(pos));
4238 bool LyXParagraph::IsLineSeparator(size_type pos) const
4240 return IsLineSeparatorChar(GetChar(pos));
4244 bool LyXParagraph::IsKomma(size_type pos) const
4246 return IsKommaChar(GetChar(pos));
4250 /// Used by the spellchecker
4251 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4253 value_type c = GetChar(pos);
4254 if (IsLetterChar(c))
4256 // '\0' is not a letter, allthough every string contains "" (below)
4259 // We want to pass the ' and escape chars to ispell
4260 string extra = lyxrc.isp_esc_chars + '\'';
4264 return contains(extra, ch);
4268 bool LyXParagraph::IsWord(size_type pos ) const
4270 return IsWordChar(GetChar(pos)) ;
4275 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4278 return FirstPhysicalPar()->getParLanguage(bparams);
4279 else if (size() > 0)
4283 return GetFirstFontSettings().language();
4286 for (size_type pos = 0; pos < size(); ++pos)
4288 return GetFontSettings(bparams, pos).language();
4289 return GetFirstFontSettings().language();
4293 return previous->getParLanguage(bparams);
4295 return bparams.language_info;
4299 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4301 return lyxrc.rtl_support && !table
4302 && getParLanguage(bparams)->RightToLeft();
4306 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4307 Language const * from, Language const * to)
4309 for(size_type i = 0; i < size(); ++i) {
4310 LyXFont font = GetFontSettings(bparams, i);
4311 if (font.language() == from) {
4312 font.setLanguage(to);
4319 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4321 Language const * doc_language =
4322 bparams.language_info;
4323 for(size_type i = 0; i < size(); ++i) {
4324 LyXFont font = GetFontSettings(bparams, i);
4325 if (font.language() != doc_language)
4332 // Convert the paragraph to a string.
4333 // Used for building the table of contents
4334 string LyXParagraph::String(Buffer const * buffer, bool label)
4336 BufferParams const & bparams = buffer->params;
4338 if (label && !IsDummy() && !labelstring.empty())
4339 s += labelstring + ' ';
4340 string::size_type len = s.size();
4342 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4343 value_type c = GetChar(i);
4346 else if (c == META_INSET &&
4347 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4349 std::ostringstream ost;
4350 GetInset(i)->Ascii(buffer, ost);
4353 GetInset(i)->Ascii(buffer, ost);
4356 s += subst(ost.str(),'\n',' ');
4361 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4362 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4363 s += NextAfterFootnote()->String(buffer, false);
4368 if (isRightToLeftPar(bparams))
4369 reverse(s.begin() + len,s.end());
4375 string LyXParagraph::String(Buffer const * buffer,
4376 LyXParagraph::size_type beg,
4377 LyXParagraph::size_type end)
4384 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4386 if (cell >= table->NumberOfCellsInRow(actcell))
4394 if (beg == 0 && !IsDummy() && !labelstring.empty())
4395 s += labelstring + ' ';
4397 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4398 value_type c = GetChar(i);
4401 else if (c == META_INSET) {
4403 std::ostringstream ost;
4404 GetInset(i)->Ascii(buffer, ost);
4407 GetInset(i)->Ascii(buffer, ost);
4411 } else if (table && IsNewlineChar(c)) {
4412 if (cell >= table->NumberOfCellsInRow(actcell)) {
4423 //if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4424 // s += NextAfterFootnote()->String(false);
4430 void LyXParagraph::SetInsetOwner(Inset *i)
4433 for (InsetList::const_iterator cit = insetlist.begin();
4434 cit != insetlist.end(); ++cit) {
4436 (*cit).inset->setOwner(i);
4441 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4444 for (InsetList::const_iterator cit = insetlist.begin();
4445 cit != insetlist.end(); ++cit) {
4447 if ((*cit).inset->IsTextInset()) {
4448 static_cast<UpdatableInset *>
4449 ((*cit).inset)->deleteLyXText(bv);
4456 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4459 for (InsetList::const_iterator cit = insetlist.begin();
4460 cit != insetlist.end(); ++cit) {
4462 if ((*cit).inset->IsTextInset()) {
4463 static_cast<UpdatableInset *>
4464 ((*cit).inset)->resizeLyXText(bv);