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"
44 using std::lower_bound;
45 using std::upper_bound;
48 int tex_code_break_column = 72; // needs non-zero initialization. set later.
49 // this is a bad idea, but how can LyXParagraph find its buffer to get
50 // parameters? (JMarc)
51 extern BufferView * current_view;
52 extern string bibitemWidest(Painter &);
54 // this is a minibuffer
55 static char minibuffer_char;
56 static LyXFont minibuffer_font;
57 static Inset * minibuffer_inset;
60 // Initialization of the counter for the paragraph id's,
61 // declared in lyxparagraph.h
62 unsigned int LyXParagraph::paragraph_id = 0;
65 LyXParagraph::LyXParagraph()
67 text.reserve(500); // is this number too big?
69 for (int i = 0; i < 10; ++i) setCounter(i , 0);
76 footnoteflag = LyXParagraph::NO_FOOTNOTE;
77 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
79 align = LYX_ALIGN_BLOCK;
82 /* table stuff -- begin*/
84 /* table stuff -- end*/
88 bibkey = 0; // ale970302
93 // This konstruktor inserts the new paragraph in a list.
94 LyXParagraph::LyXParagraph(LyXParagraph * par)
97 par->text.resize(par->text.size());
99 for (int i = 0; i < 10; ++i) setCounter(i, 0);
103 // double linked list begin
106 next->previous = this;
108 previous->next = this;
111 footnoteflag = LyXParagraph::NO_FOOTNOTE;
112 footnotekind = LyXParagraph::FOOTNOTE;
115 /* table stuff -- begin*/
117 /* table stuff -- end*/
120 id_ = paragraph_id++;
122 bibkey = 0; // ale970302
128 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
129 BufferParams const & params,
130 char footflag, char dth) const
132 LyXFont font1, font2;
137 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
139 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
141 // The beginning or the end of a footnote environment?
142 if (footflag != footnoteflag) {
143 footflag = footnoteflag;
145 os << "\n\\begin_float "
146 << string_footnotekinds[footnotekind]
149 os << "\n\\end_float ";
153 // The beginning or end of a deeper (i.e. nested) area?
156 while (depth > dth) {
157 os << "\n\\begin_deeper ";
161 while (depth < dth) {
162 os << "\n\\end_deeper ";
168 // First write the layout
170 << textclasslist.NameOfLayout(params.textclass, layout)
173 // Maybe some vertical spaces.
174 if (added_space_top.kind() != VSpace::NONE)
175 os << "\\added_space_top "
176 << added_space_top.asLyXCommand() << " ";
177 if (added_space_bottom.kind() != VSpace::NONE)
178 os << "\\added_space_bottom "
179 << added_space_bottom.asLyXCommand() << " ";
181 // Maybe the paragraph has special spacing
182 spacing.writeFile(os, true);
184 // The labelwidth string used in lists.
185 if (!labelwidthstring.empty())
186 os << "\\labelwidthstring "
187 << labelwidthstring << '\n';
189 // Lines above or below?
193 os << "\\line_bottom ";
195 // Pagebreaks above or below?
197 os << "\\pagebreak_top ";
198 if (pagebreak_bottom)
199 os << "\\pagebreak_bottom ";
201 // Start of appendix?
202 if (start_of_appendix)
203 os << "\\start_of_appendix ";
210 if (align != LYX_ALIGN_LAYOUT) {
212 case LYX_ALIGN_LEFT: h = 1; break;
213 case LYX_ALIGN_RIGHT: h = 2; break;
214 case LYX_ALIGN_CENTER: h = 3; break;
215 default: h = 0; break;
217 os << "\\align " << string_align[h] << " ";
219 if (pextra_type != PEXTRA_NONE) {
220 os << "\\pextra_type " << pextra_type;
221 if (pextra_type == PEXTRA_MINIPAGE) {
222 os << " \\pextra_alignment "
225 os << " \\pextra_hfill "
227 if (pextra_start_minipage)
228 os << " \\pextra_start_minipage "
229 << pextra_start_minipage;
231 if (!pextra_width.empty()) {
232 os << " \\pextra_width "
233 << VSpace(pextra_width).asLyXCommand();
234 } else if (!pextra_widthp.empty()) {
235 os << " \\pextra_widthp "
241 // Dummy layout. This means that a footnote ended.
242 os << "\n\\end_float ";
243 footflag = LyXParagraph::NO_FOOTNOTE;
246 // It might be a table.
248 os << "\\LyXTable\n";
254 bibkey->Write(buf, os);
256 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
259 for (size_type i = 0; i < size(); ++i) {
265 // Write font changes
266 font2 = GetFontSettings(params, i);
267 if (font2 != font1) {
268 font2.lyxWriteChanges(font1, os);
277 Inset const * inset = GetInset(i);
279 if (inset->DirectWrite()) {
280 // international char, let it write
281 // code directly so it's shorter in
283 inset->Write(buf, os);
285 os << "\n\\begin_inset ";
286 inset->Write(buf, os);
287 os << "\n\\end_inset \n\n";
293 os << "\n\\newline \n";
297 os << "\n\\hfill \n";
301 os << "\n\\backslash \n";
305 if (i + 1 < size() && GetChar(i + 1) == ' ') {
312 if ((column > 70 && c == ' ')
317 // this check is to amend a bug. LyX sometimes
318 // inserts '\0' this could cause problems.
322 lyxerr << "ERROR (LyXParagraph::writeFile):"
323 " NULL char in structure." << endl;
329 // now write the next paragraph
331 next->writeFile(buf, os, params, footflag, dth);
335 void LyXParagraph::validate(LaTeXFeatures & features) const
337 BufferParams const & params = features.bufferParams();
339 // this will be useful later
340 LyXLayout const & layout =
341 textclasslist.Style(params.textclass,
345 if (line_top || line_bottom)
346 features.lyxline = true;
347 if (!spacing.isDefault())
348 features.setspace = true;
351 features.layout[GetLayout()] = true;
354 Language const * doc_language = params.language_info;
356 for (FontList::const_iterator cit = fontlist.begin();
357 cit != fontlist.end(); ++cit) {
358 if ((*cit).font.noun() == LyXFont::ON) {
359 lyxerr[Debug::LATEX] << "font.noun: "
360 << (*cit).font.noun()
362 features.noun = true;
363 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
364 << (*cit).font.stateText(0)
367 switch ((*cit).font.color()) {
369 case LColor::inherit:
373 features.color = true;
374 lyxerr[Debug::LATEX] << "Color enabled. Font: "
375 << (*cit).font.stateText(0)
379 Language const * language = (*cit).font.language();
380 if (language != doc_language) {
381 features.UsedLanguages.insert(language);
382 lyxerr[Debug::LATEX] << "Found language "
383 << language->lang() << endl;
388 for (InsetList::const_iterator cit = insetlist.begin();
389 cit != insetlist.end(); ++cit) {
391 (*cit).inset->Validate(features);
394 if (table && table->IsLongTable())
395 features.longtable = true;
396 if (pextra_type == PEXTRA_INDENT)
397 features.LyXParagraphIndent = true;
398 if (pextra_type == PEXTRA_FLOATFLT)
399 features.floatflt = true;
400 if (layout.needprotect
401 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
402 features.NeedLyXFootnoteCode = true;
403 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
404 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
405 features.NeedLyXMinipageIndent = true;
406 if (table && table->NeedRotating())
407 features.rotating = true;
408 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
409 features.algorithm = true;
413 // First few functions needed for cut and paste and paragraph breaking.
414 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
415 LyXParagraph::size_type pos) const
417 minibuffer_char = GetChar(pos);
418 minibuffer_font = GetFontSettings(bparams, pos);
419 minibuffer_inset = 0;
420 if (minibuffer_char == LyXParagraph::META_INSET) {
422 minibuffer_inset = GetInset(pos)->Clone();
424 minibuffer_inset = 0;
425 minibuffer_char = ' ';
426 // This reflects what GetInset() does (ARRae)
432 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
433 LyXParagraph::size_type pos)
435 minibuffer_char = GetChar(pos);
436 minibuffer_font = GetFontSettings(bparams, pos);
437 minibuffer_inset = 0;
438 if (minibuffer_char == LyXParagraph::META_INSET) {
440 minibuffer_inset = GetInset(pos);
441 // This is a little hack since I want exactly
442 // the inset, not just a clone. Otherwise
443 // the inset would be deleted when calling Erase(pos)
445 InsetList::iterator it = lower_bound(insetlist.begin(),
448 if (it != insetlist.end() && (*it).pos == pos)
451 minibuffer_inset = 0;
452 minibuffer_char = ' ';
453 // This reflects what GetInset() does (ARRae)
458 // Erase(pos); now the caller is responsible for that.
462 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
464 if ((minibuffer_char == LyXParagraph::META_INSET) &&
465 !InsertInsetAllowed(minibuffer_inset))
468 if (minibuffer_char == LyXParagraph::META_INSET)
469 InsertInset(pos, minibuffer_inset, minibuffer_font);
471 InsertChar(pos, minibuffer_char, minibuffer_font);
473 InsertChar(pos, minibuffer_char);
474 SetFont(pos, minibuffer_font);
475 if (minibuffer_char == LyXParagraph::META_INSET)
476 InsertInset(pos, minibuffer_inset);
485 void LyXParagraph::Clear()
490 pagebreak_top = false;
491 pagebreak_bottom = false;
493 added_space_top = VSpace(VSpace::NONE);
494 added_space_bottom = VSpace(VSpace::NONE);
495 spacing.set(Spacing::Default);
497 align = LYX_ALIGN_LAYOUT;
501 pextra_type = PEXTRA_NONE;
502 pextra_width.erase();
503 pextra_widthp.erase();
504 pextra_alignment = MINIPAGE_ALIGN_TOP;
505 pextra_hfill = false;
506 pextra_start_minipage = false;
509 labelwidthstring.erase();
513 start_of_appendix = false;
517 // the destructor removes the new paragraph from the list
518 LyXParagraph::~LyXParagraph()
521 previous->next = next;
523 next->previous = previous;
525 for (InsetList::iterator it = insetlist.begin();
526 it != insetlist.end(); ++it) {
530 /* table stuff -- begin*/
532 /* table stuff -- end*/
538 //lyxerr << "LyXParagraph::paragraph_id = "
539 // << LyXParagraph::paragraph_id << endl;
543 void LyXParagraph::Erase(LyXParagraph::size_type pos)
545 // > because last is the next unused position, and you can
546 // use it if you want
549 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
550 NextAfterFootnote()->Erase(pos - text.size() - 1);
553 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
554 "position does not exist." << endl;
557 if (pos < size()) { // last is free for insertation, but should be empty
558 // if it is an inset, delete the inset entry
559 if (text[pos] == LyXParagraph::META_INSET) {
561 InsetList::iterator it = lower_bound(insetlist.begin(),
564 if (it != insetlist.end() && (*it).pos == pos) {
569 text.erase(text.begin() + pos);
571 // Erase entries in the tables.
572 FontList::iterator it = lower_bound(fontlist.begin(),
575 if (it != fontlist.end() && (*it).pos == pos &&
577 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
578 // If it is a multi-character font
579 // entry, we just make it smaller
580 // (see update below), otherwise we
582 unsigned int i = it - fontlist.begin();
583 fontlist.erase(fontlist.begin() + i);
584 it = fontlist.begin() + i;
585 if (i > 0 && i < fontlist.size() &&
586 fontlist[i-1].font == fontlist[i].font) {
587 fontlist.erase(fontlist.begin() + i-1);
588 it = fontlist.begin() + i-1;
592 // Update all other entries.
593 for (; it != fontlist.end(); ++it)
596 // Update the inset table.
597 for (InsetList::iterator it = upper_bound(insetlist.begin(),
600 it != insetlist.end(); ++it)
603 lyxerr << "ERROR (LyXParagraph::Erase): "
604 "can't erase non-existant char." << endl;
609 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
612 // > because last is the next unused position, and you can
613 // use it if you want
617 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
618 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
622 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
623 "position does not exist." << endl;
626 text.insert(text.begin() + pos, c);
627 // Update the font table.
628 for (FontList::iterator it = lower_bound(fontlist.begin(),
631 it != fontlist.end(); ++it)
634 // Update the inset table.
635 for (InsetList::iterator it = lower_bound(insetlist.begin(),
638 it != insetlist.end(); ++it)
641 LyXFont f(LyXFont::ALL_INHERIT);
642 InsertChar(pos, c, f);
648 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
649 char c, LyXFont const & font)
651 // > because last is the next unused position, and you can
652 // use it if you want
656 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
657 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
661 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
662 "position does not exist." << endl;
665 text.insert(text.begin() + pos, c);
666 // Update the font table.
667 for (FontList::iterator it = lower_bound(fontlist.begin(),
670 it != fontlist.end(); ++it)
673 // Update the inset table.
674 for (InsetList::iterator it = lower_bound(insetlist.begin(),
677 it != insetlist.end(); ++it)
685 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
689 LyXFont f(LyXFont::ALL_INHERIT);
690 InsertInset(pos, inset, f);
692 // > because last is the next unused position, and you can
693 // use it if you want
697 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
699 ->InsertInset(pos - text.size() - 1, inset);
702 lyxerr << "ERROR (LyXParagraph::InsertInset): "
703 "position does not exist: " << pos << endl;
706 if (text[pos] != LyXParagraph::META_INSET) {
707 lyxerr << "ERROR (LyXParagraph::InsertInset): "
708 "there is no LyXParagraph::META_INSET" << endl;
713 // Add a new entry in the inset table.
714 InsetList::iterator it = lower_bound(insetlist.begin(),
717 if (it != insetlist.end() && (*it).pos == pos)
718 lyxerr << "ERROR (LyXParagraph::InsertInset): "
719 "there is an inset in position: " << pos << endl;
721 insetlist.insert(it, InsetTable(pos,inset));
723 inset->setOwner(inset_owner);
730 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
731 Inset * inset, LyXFont const & font)
735 // > because last is the next unused position, and you can
736 // use it if you want
740 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
742 ->InsertInset(pos - text.size() - 1,
746 lyxerr << "ERROR (LyXParagraph::InsertInset): "
747 "position does not exist: " << pos << endl;
751 InsertChar(pos, META_INSET, font);
752 Assert(text[pos] == META_INSET);
754 // Add a new entry in the inset table.
755 InsetList::iterator it = lower_bound(insetlist.begin(),
758 if (it != insetlist.end() && (*it).pos == pos)
759 lyxerr << "ERROR (LyXParagraph::InsertInset): "
760 "there is an inset in position: " << pos << endl;
762 insetlist.insert(it, InsetTable(pos, inset));
764 inset->setOwner(inset_owner);
769 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
772 return inset_owner->InsertInsetAllowed(inset);
777 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
782 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
783 return NextAfterFootnote()
784 ->GetInset(pos - text.size() - 1);
787 lyxerr << "ERROR (LyXParagraph::GetInset): "
788 "position does not exist: "
794 InsetList::iterator it = lower_bound(insetlist.begin(),
797 if (it != insetlist.end() && (*it).pos == pos)
800 lyxerr << "ERROR (LyXParagraph::GetInset): "
801 "Inset does not exist: " << pos << endl;
804 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
805 // Did this commenting out introduce a bug? So far I have not
806 // see any, please enlighten me. (Lgb)
807 // My guess is that since the inset does not exist, we might
808 // as well replace it with a space to prevent craches. (Asger)
813 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
818 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
819 return NextAfterFootnote()
820 ->GetInset(pos - text.size() - 1);
823 lyxerr << "ERROR (LyXParagraph::GetInset): "
824 "position does not exist: "
830 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
833 if (cit != insetlist.end() && (*cit).pos == pos)
836 lyxerr << "ERROR (LyXParagraph::GetInset): "
837 "Inset does not exist: " << pos << endl;
839 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
840 // Did this commenting out introduce a bug? So far I have not
841 // see any, please enlighten me. (Lgb)
842 // My guess is that since the inset does not exist, we might
843 // as well replace it with a space to prevent craches. (Asger)
848 // Gets uninstantiated font setting at position.
849 // Optimized after profiling. (Asger)
850 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
851 LyXParagraph::size_type pos) const
854 FontList::const_iterator cit = lower_bound(fontlist.begin(),
857 if (cit != fontlist.end())
860 // > because last is the next unused position, and you can
861 // use it if you want
862 else if (pos > size()) {
865 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
866 return NextAfterFootnote()
867 ->GetFontSettings(bparams,
868 pos - text.size() - 1);
871 // Why is it an error to ask for the font of a
872 // position that does not exist? Would it be
873 // enough for this to be enabled on debug?
874 // We want strict error checking, but it's ok to only
875 // have it when debugging. (Asger)
876 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
877 "position does not exist. "
878 << pos << " (" << static_cast<int>(pos)
880 } else if (pos > 0) {
881 return GetFontSettings(bparams, pos - 1);
882 } else // pos = size() = 0
883 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
885 return LyXFont(LyXFont::ALL_INHERIT);
888 // Gets uninstantiated font setting at position 0
889 LyXFont LyXParagraph::GetFirstFontSettings() const
892 if (!fontlist.empty())
893 return fontlist[0].font;
897 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
898 return NextAfterFootnote()->GetFirstFontSettings();
900 return LyXFont(LyXFont::ALL_INHERIT);
904 // Gets the fully instantiated font at a given position in a paragraph
905 // This is basically the same function as LyXText::GetFont() in text2.C.
906 // The difference is that this one is used for generating the LaTeX file,
907 // and thus cosmetic "improvements" are disallowed: This has to deliver
908 // the true picture of the buffer. (Asger)
909 // If position is -1, we get the layout font of the paragraph.
910 // If position is -2, we get the font of the manual label of the paragraph.
911 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
912 LyXParagraph::size_type pos) const
915 LyXLayout const & layout =
916 textclasslist.Style(bparams.textclass,
918 LyXParagraph::size_type main_body = 0;
919 if (layout.labeltype == LABEL_MANUAL)
920 main_body = BeginningOfMainBody();
925 layoutfont = layout.labelfont;
927 layoutfont = layout.font;
928 tmpfont = GetFontSettings(bparams, pos);
929 tmpfont.realize(layoutfont);
931 // process layoutfont for pos == -1 and labelfont for pos < -1
933 tmpfont = layout.font;
935 tmpfont = layout.labelfont;
936 tmpfont.setLanguage(getParLanguage(bparams));
939 // check for environment font information
940 char par_depth = GetDepth();
941 LyXParagraph const * par = this;
942 while (par && par_depth && !tmpfont.resolved()) {
943 par = par->DepthHook(par_depth - 1);
945 tmpfont.realize(textclasslist.
946 Style(bparams.textclass,
947 par->GetLayout()).font);
948 par_depth = par->GetDepth();
952 tmpfont.realize(textclasslist
953 .TextClass(bparams.textclass)
959 /// Returns the height of the highest font in range
961 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
962 LyXParagraph::size_type endpos) const
964 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
965 if (fontlist.empty())
968 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
971 if (end_it != fontlist.end())
974 for (FontList::const_iterator cit = lower_bound(fontlist.begin(),
976 startpos, matchFT());
977 cit != end_it; ++cit) {
978 LyXFont::FONT_SIZE size = (*cit).font.size();
979 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
986 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
993 // > because last is the next unused position, and you can
994 // use it if you want
995 else if (pos > size()) {
997 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
998 return NextAfterFootnote()
999 ->GetChar(pos - text.size() - 1);
1003 lyxerr << "ERROR (LyXParagraph::GetChar): "
1004 "position does not exist."
1005 << pos << " (" << static_cast<int>(pos)
1007 // Assert(false); // This triggers sometimes...
1016 // We should have a footnote environment.
1017 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1018 // Notice that LyX does request the
1019 // last char from time to time. (Asger)
1020 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1021 // "expected footnote." << endl;
1024 switch (next->footnotekind) {
1025 case LyXParagraph::FOOTNOTE:
1026 return LyXParagraph::META_FOOTNOTE;
1027 case LyXParagraph::MARGIN:
1028 return LyXParagraph::META_MARGIN;
1029 case LyXParagraph::FIG:
1030 case LyXParagraph::WIDE_FIG:
1031 return LyXParagraph::META_FIG;
1032 case LyXParagraph::TAB:
1033 case LyXParagraph::WIDE_TAB:
1034 return LyXParagraph::META_TAB;
1035 case LyXParagraph::ALGORITHM:
1036 return LyXParagraph::META_ALGORITHM;
1038 return '\0'; // to shut up gcc
1044 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
1051 // > because last is the next unused position, and you can
1052 // use it if you want
1053 else if (pos > size()) {
1055 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1056 return NextAfterFootnote()
1057 ->GetChar(pos - text.size() - 1);
1061 lyxerr << "ERROR (LyXParagraph::GetChar const): "
1062 "position does not exist."
1063 << pos << " (" << static_cast<int>(pos)
1071 // We should have a footnote environment.
1072 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1073 // Notice that LyX does request the
1074 // last char from time to time. (Asger)
1075 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1076 // "expected footnote." << endl;
1079 switch (next->footnotekind) {
1080 case LyXParagraph::FOOTNOTE:
1081 return LyXParagraph::META_FOOTNOTE;
1082 case LyXParagraph::MARGIN:
1083 return LyXParagraph::META_MARGIN;
1084 case LyXParagraph::FIG:
1085 case LyXParagraph::WIDE_FIG:
1086 return LyXParagraph::META_FIG;
1087 case LyXParagraph::TAB:
1088 case LyXParagraph::WIDE_TAB:
1089 return LyXParagraph::META_TAB;
1090 case LyXParagraph::ALGORITHM:
1091 return LyXParagraph::META_ALGORITHM;
1093 return '\0'; // to shut up gcc
1099 // return an string of the current word, and the end of the word in lastpos.
1100 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1104 // the current word is defined as starting at the first character
1105 // from the immediate left of lastpospos which meets the definition
1106 // of IsLetter(), continuing to the last character to the right
1107 // of this meeting IsLetter.
1113 // move back until we have a letter
1115 //there's no real reason to have firstpos & lastpos as
1116 //separate variables as this is written, but maybe someon
1117 // will want to return firstpos in the future.
1119 //since someone might have typed a punctuation first
1120 int firstpos = lastpos;
1122 while ((firstpos >= 0) && !IsLetter(firstpos))
1125 // now find the beginning by looking for a nonletter
1127 while ((firstpos>= 0) && IsLetter(firstpos))
1130 // the above is now pointing to the preceeding non-letter
1134 // so copy characters into theword until we get a nonletter
1135 // note that this can easily exceed lastpos, wich means
1136 // that if used in the middle of a word, the whole word
1139 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1146 LyXParagraph::size_type LyXParagraph::Last() const
1149 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1150 return text.size() + NextAfterFootnote()->Last() + 1;
1151 // the 1 is the symbol
1159 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1161 // > because last is the next unused position, and you can
1162 // use it if you want
1166 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1167 return NextAfterFootnote()
1168 ->ParFromPos(pos - text.size() - 1);
1171 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1172 "position does not exist." << endl;
1179 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1181 // > because last is the next unused position, and you can
1182 // use it if you want
1186 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1187 return NextAfterFootnote()
1188 ->PositionInParFromPos(pos - text.size() - 1);
1192 "ERROR (LyXParagraph::PositionInParFromPos): "
1193 "position does not exist." << endl;
1201 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1202 LyXFont const & font)
1204 // > because last is the next unused position, and you can
1205 // use it if you want
1209 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1210 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1214 lyxerr << "ERROR (LyXParagraph::SetFont): "
1215 "position does not exist." << endl;
1220 // First, reduce font against layout/label font
1221 // Update: The SetCharFont() routine in text2.C already
1222 // reduces font, so we don't need to do that here. (Asger)
1223 // No need to simplify this because it will disappear
1224 // in a new kernel. (Asger)
1225 // Next search font table
1227 FontList::iterator it = lower_bound(fontlist.begin(),
1230 unsigned int i = it - fontlist.begin();
1231 bool notfound = it == fontlist.end();
1233 if (!notfound && fontlist[i].font == font)
1236 bool begin = pos == 0 || notfound ||
1237 (i > 0 && fontlist[i-1].pos == pos - 1);
1238 // Is position pos is a beginning of a font block?
1239 bool end = !notfound && fontlist[i].pos == pos;
1240 // Is position pos is the end of a font block?
1241 if (begin && end) { // A single char block
1242 if (i+1 < fontlist.size() &&
1243 fontlist[i+1].font == font) {
1244 // Merge the singleton block with the next block
1245 fontlist.erase(fontlist.begin() + i);
1246 if (i > 0 && fontlist[i-1].font == font)
1247 fontlist.erase(fontlist.begin() + i-1);
1248 } else if (i > 0 && fontlist[i-1].font == font) {
1249 // Merge the singleton block with the previous block
1250 fontlist[i-1].pos = pos;
1251 fontlist.erase(fontlist.begin() + i);
1253 fontlist[i].font = font;
1255 if (i > 0 && fontlist[i-1].font == font)
1256 fontlist[i-1].pos = pos;
1258 fontlist.insert(fontlist.begin() + i,
1259 FontTable(pos, font));
1261 fontlist[i].pos = pos - 1;
1262 if (!(i+1 < fontlist.size() &&
1263 fontlist[i+1].font == font))
1264 fontlist.insert(fontlist.begin() + i+1,
1265 FontTable(pos, font));
1266 } else { // The general case. The block is splitted into 3 blocks
1267 fontlist.insert(fontlist.begin() + i,
1268 FontTable(pos - 1, fontlist[i].font));
1269 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1274 // This function is able to hide closed footnotes.
1275 LyXParagraph * LyXParagraph::Next()
1278 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1279 LyXParagraph * tmp = next;
1281 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1283 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1284 return tmp->Next(); /* there can be more than one
1285 footnote in a logical
1288 return next; // This should never happen!
1295 LyXParagraph * LyXParagraph::NextAfterFootnote()
1298 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1299 LyXParagraph * tmp = next;
1300 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1302 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1303 return tmp; /* there can be more than one footnote
1304 in a logical paragraph */
1306 return next; // This should never happen!
1313 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1316 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1317 LyXParagraph * tmp = next;
1318 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1320 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1321 return tmp; /* there can be more than one footnote
1322 in a logical paragraph */
1324 return next; // This should never happen!
1331 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1335 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1337 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1338 tmp = tmp->previous;
1339 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1340 return tmp; /* there can be more than one footnote
1341 in a logical paragraph */
1343 return previous; // This should never happen!
1350 LyXParagraph * LyXParagraph::LastPhysicalPar()
1353 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1356 LyXParagraph * tmp = this;
1358 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1359 tmp = tmp->NextAfterFootnote();
1367 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1370 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1373 LyXParagraph const * tmp = this;
1375 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1376 tmp = tmp->NextAfterFootnote();
1384 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1389 LyXParagraph * tmppar = this;
1393 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1394 tmppar = tmppar->previous;
1406 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1411 LyXParagraph const * tmppar = this;
1415 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1416 tmppar = tmppar->previous;
1428 // This function is able to hide closed footnotes.
1429 LyXParagraph * LyXParagraph::Previous()
1431 LyXParagraph * tmp = previous;
1437 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1438 tmp = tmp->previous;
1440 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1441 tmp = tmp->previous;
1442 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1443 return tmp->next->Previous();
1453 // This function is able to hide closed footnotes.
1454 LyXParagraph const * LyXParagraph::Previous() const
1456 LyXParagraph * tmp = previous;
1461 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1462 tmp = tmp->previous;
1464 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1465 tmp = tmp->previous;
1466 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1467 return tmp->next->Previous();
1477 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1478 LyXParagraph::size_type pos,
1481 size_type i, j, pos_end, pos_first;
1482 // create a new paragraph
1483 LyXParagraph * par = ParFromPos(pos);
1484 LyXParagraph * firstpar = FirstPhysicalPar();
1486 LyXParagraph * tmp = new LyXParagraph(par);
1489 tmp->footnoteflag = footnoteflag;
1490 tmp->footnotekind = footnotekind;
1492 // this is an idea for a more userfriendly layout handling, I will
1493 // see what the users say
1495 // layout stays the same with latex-environments
1497 tmp->SetOnlyLayout(bparams, firstpar->layout);
1498 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1501 if (Last() > pos || !Last() || flag == 2) {
1502 tmp->SetOnlyLayout(bparams, firstpar->layout);
1503 tmp->align = firstpar->align;
1504 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1506 tmp->line_bottom = firstpar->line_bottom;
1507 firstpar->line_bottom = false;
1508 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1509 firstpar->pagebreak_bottom = false;
1510 tmp->added_space_bottom = firstpar->added_space_bottom;
1511 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1513 tmp->depth = firstpar->depth;
1514 tmp->noindent = firstpar->noindent;
1516 // copy everything behind the break-position
1517 // to the new paragraph
1519 while (ParFromPos(pos_first) != par)
1522 pos_end = pos_first + par->text.size() - 1;
1524 for (i = j = pos; i <= pos_end; ++i) {
1525 par->CutIntoMinibuffer(bparams, i - pos_first);
1526 if (tmp->InsertFromMinibuffer(j - pos))
1529 tmp->text.resize(tmp->text.size());
1530 for (i = pos_end; i >= pos; --i)
1531 par->Erase(i - pos_first);
1533 par->text.resize(par->text.size());
1536 // just an idea of me
1538 tmp->line_top = firstpar->line_top;
1539 tmp->pagebreak_top = firstpar->pagebreak_top;
1540 tmp->added_space_top = firstpar->added_space_top;
1541 tmp->bibkey = firstpar->bibkey;
1543 // layout stays the same with latex-environments
1545 firstpar->SetOnlyLayout(bparams, tmp->layout);
1546 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1547 firstpar->depth = tmp->depth;
1553 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1555 par = par->FirstPhysicalPar();
1557 footnoteflag = par->footnoteflag;
1558 footnotekind = par->footnotekind;
1560 layout = par->layout;
1561 align = par-> align;
1562 SetLabelWidthString(par->labelwidthstring);
1564 line_bottom = par->line_bottom;
1565 pagebreak_bottom = par->pagebreak_bottom;
1566 added_space_bottom = par->added_space_bottom;
1568 line_top = par->line_top;
1569 pagebreak_top = par->pagebreak_top;
1570 added_space_top = par->added_space_top;
1572 spacing = par->spacing;
1574 pextra_type = par->pextra_type;
1575 pextra_width = par->pextra_width;
1576 pextra_widthp = par->pextra_widthp;
1577 pextra_alignment = par->pextra_alignment;
1578 pextra_hfill = par->pextra_hfill;
1579 pextra_start_minipage = par->pextra_start_minipage;
1581 noindent = par->noindent;
1587 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1589 LyXParagraph * tmppar = this;
1592 && tmppar->previous->footnoteflag ==
1593 LyXParagraph::CLOSED_FOOTNOTE)
1594 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1595 tmppar = tmppar->previous;
1598 return this; // This should never happen!
1605 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1607 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1611 if (!IsDummy() && !table){
1613 && (IsNewline(0) || IsLineSeparator(0))){
1622 LyXParagraph * LyXParagraph::Clone() const
1624 // create a new paragraph
1625 LyXParagraph * result = new LyXParagraph;
1627 result->MakeSameLayout(this);
1629 // this is because of the dummy layout of the paragraphs that
1631 result->layout = layout;
1634 /* table stuff -- begin*/
1636 result->table = table->Clone();
1639 /* table stuff -- end*/
1641 result->inset_owner = inset_owner;
1644 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1647 // copy everything behind the break-position to the new paragraph
1649 result->text = text;
1650 result->fontlist = fontlist;
1651 result->insetlist = insetlist;
1652 for (InsetList::iterator it = result->insetlist.begin();
1653 it != result->insetlist.end(); ++it)
1654 (*it).inset = (*it).inset->Clone();
1659 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1661 par = par->FirstPhysicalPar();
1665 par->footnoteflag == footnoteflag &&
1666 par->footnotekind == footnotekind &&
1668 par->layout == layout &&
1670 par->align == align &&
1672 par->line_bottom == line_bottom &&
1673 par->pagebreak_bottom == pagebreak_bottom &&
1674 par->added_space_bottom == added_space_bottom &&
1676 par->line_top == line_top &&
1677 par->pagebreak_top == pagebreak_top &&
1678 par->added_space_top == added_space_top &&
1680 par->spacing == spacing &&
1682 par->pextra_type == pextra_type &&
1683 par->pextra_width == pextra_width &&
1684 par->pextra_widthp == pextra_widthp &&
1685 par->pextra_alignment == pextra_alignment &&
1686 par->pextra_hfill == pextra_hfill &&
1687 par->pextra_start_minipage == pextra_start_minipage &&
1689 par->table == table && // what means: NO TABLE AT ALL
1692 par->noindent == noindent &&
1693 par->depth == depth);
1697 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1698 LyXParagraph::size_type pos)
1700 // create a new paragraph
1701 LyXParagraph * par = ParFromPos(pos);
1703 LyXParagraph * tmp = new LyXParagraph(par);
1705 tmp->MakeSameLayout(par);
1707 // When can pos < Last()?
1708 // I guess pos == Last() is possible.
1710 // copy everything behind the break-position to the new
1712 size_type pos_first = 0;
1713 while (ParFromPos(pos_first) != par)
1715 size_type pos_end = pos_first + par->text.size() - 1;
1718 for (i = j = pos; i <= pos_end; ++i) {
1719 par->CutIntoMinibuffer(bparams, i - pos_first);
1720 if (tmp->InsertFromMinibuffer(j - pos))
1723 tmp->text.resize(tmp->text.size());
1724 for (size_type i = pos_end; i >= pos; --i)
1725 par->Erase(i - pos_first);
1727 par->text.resize(par->text.size());
1732 // Be carefull, this does not make any check at all.
1733 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1735 // copy the next paragraph to this one
1736 LyXParagraph * the_next = Next();
1738 LyXParagraph * firstpar = FirstPhysicalPar();
1740 // first the DTP-stuff
1741 firstpar->line_bottom = the_next->line_bottom;
1742 firstpar->added_space_bottom = the_next->added_space_bottom;
1743 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1745 size_type pos_end = the_next->text.size() - 1;
1746 size_type pos_insert = Last();
1748 // ok, now copy the paragraph
1750 for (i = j = 0; i <= pos_end; ++i) {
1751 the_next->CutIntoMinibuffer(bparams, i);
1752 if (InsertFromMinibuffer(pos_insert + j))
1756 // delete the next paragraph
1757 LyXParagraph * ppar = the_next->previous;
1758 LyXParagraph * npar = the_next->next;
1765 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1767 LyXParagraph * par = ParFromPos(pos);
1769 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1770 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1776 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1778 LyXParagraph * par = ParFromPos(pos);
1780 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1781 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1787 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1789 LyXParagraph const * par = this;
1790 int par_depth = GetDepth();
1792 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1794 textclasslist.Style(bparams.textclass,
1795 layout).endlabeltype;
1796 if (endlabeltype != END_LABEL_NO_LABEL) {
1797 LyXParagraph const * last = this;
1798 if( footnoteflag == NO_FOOTNOTE)
1799 last = LastPhysicalPar();
1800 else if (next->footnoteflag == NO_FOOTNOTE)
1801 return endlabeltype;
1803 if (!last || !last->next)
1804 return endlabeltype;
1806 int next_depth = last->next->GetDepth();
1807 if (par_depth > next_depth ||
1808 (par_depth == next_depth && layout != last->next->GetLayout() ))
1809 return endlabeltype;
1814 par = par->DepthHook(par_depth - 1);
1816 par_depth = par->GetDepth();
1818 return END_LABEL_NO_LABEL;
1822 LyXTextClass::size_type LyXParagraph::GetLayout() const
1824 return FirstPhysicalPar()->layout;
1828 char LyXParagraph::GetDepth() const
1830 return FirstPhysicalPar()->depth;
1834 char LyXParagraph::GetAlign() const
1836 return FirstPhysicalPar()->align;
1840 string LyXParagraph::GetLabelstring() const
1842 return FirstPhysicalPar()->labelstring;
1846 int LyXParagraph::GetFirstCounter(int i) const
1848 return FirstPhysicalPar()->counter_[i];
1852 // the next two functions are for the manual labels
1853 string LyXParagraph::GetLabelWidthString() const
1855 if (!FirstPhysicalPar()->labelwidthstring.empty())
1856 return FirstPhysicalPar()->labelwidthstring;
1858 return _("Senseless with this layout!");
1862 void LyXParagraph::SetLabelWidthString(string const & s)
1864 LyXParagraph * par = FirstPhysicalPar();
1866 par->labelwidthstring = s;
1870 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1871 LyXTextClass::size_type new_layout)
1873 LyXParagraph * par = FirstPhysicalPar();
1874 LyXParagraph * ppar = 0;
1875 LyXParagraph * npar = 0;
1877 par->layout = new_layout;
1879 /* table stuff -- begin*/
1882 /* table stuff -- end*/
1884 if (par->pextra_type == PEXTRA_NONE) {
1885 if (par->Previous()) {
1886 ppar = par->Previous()->FirstPhysicalPar();
1889 && (ppar->depth > par->depth))
1890 ppar = ppar->Previous()->FirstPhysicalPar();
1893 npar = par->Next()->NextAfterFootnote();
1896 && (npar->depth > par->depth))
1897 npar = npar->Next()->NextAfterFootnote();
1899 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1901 p1 = ppar->pextra_width,
1902 p2 = ppar->pextra_widthp;
1903 ppar->SetPExtraType(bparams, ppar->pextra_type,
1904 p1.c_str(), p2.c_str());
1906 if ((par->pextra_type == PEXTRA_NONE) &&
1907 npar && (npar->pextra_type != PEXTRA_NONE)) {
1909 p1 = npar->pextra_width,
1910 p2 = npar->pextra_widthp;
1911 npar->SetPExtraType(bparams, npar->pextra_type,
1912 p1.c_str(), p2.c_str());
1918 void LyXParagraph::SetLayout(BufferParams const & bparams,
1919 LyXTextClass::size_type new_layout)
1922 * par = FirstPhysicalPar(),
1926 par->layout = new_layout;
1927 par->labelwidthstring.erase();
1928 par->align = LYX_ALIGN_LAYOUT;
1929 par->added_space_top = VSpace(VSpace::NONE);
1930 par->added_space_bottom = VSpace(VSpace::NONE);
1931 par->spacing.set(Spacing::Default);
1934 /* table stuff -- begin*/
1937 /* table stuff -- end*/
1939 if (par->pextra_type == PEXTRA_NONE) {
1940 if (par->Previous()) {
1941 ppar = par->Previous()->FirstPhysicalPar();
1944 && (ppar->depth > par->depth))
1945 ppar = ppar->Previous()->FirstPhysicalPar();
1948 npar = par->Next()->NextAfterFootnote();
1951 && (npar->depth > par->depth))
1952 npar = npar->Next()->NextAfterFootnote();
1954 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1956 p1 = ppar->pextra_width,
1957 p2 = ppar->pextra_widthp;
1958 ppar->SetPExtraType(bparams, ppar->pextra_type,
1959 p1.c_str(), p2.c_str());
1961 if ((par->pextra_type == PEXTRA_NONE) &&
1962 npar && (npar->pextra_type != PEXTRA_NONE)) {
1964 p1 = npar->pextra_width,
1965 p2 = npar->pextra_widthp;
1966 npar->SetPExtraType(bparams, npar->pextra_type,
1967 p1.c_str(), p2.c_str());
1973 // if the layout of a paragraph contains a manual label, the beginning of the
1974 // main body is the beginning of the second word. This is what the par-
1975 // function returns. If the layout does not contain a label, the main
1976 // body always starts with position 0. This differentiation is necessary,
1977 // because there cannot be a newline or a blank <= the beginning of the
1978 // main body in TeX.
1980 int LyXParagraph::BeginningOfMainBody() const
1982 if (FirstPhysicalPar() != this)
1985 // Unroll the first two cycles of the loop
1986 // and remember the previous character to
1987 // remove unnecessary GetChar() calls
1990 && GetChar(i) != LyXParagraph::META_NEWLINE
1993 char previous_char = 0, temp = 0;
1995 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1996 // Yes, this ^ is supposed to be "= " not "=="
1999 && previous_char != ' '
2000 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2002 previous_char = temp;
2007 if (i == 0 && i == size() &&
2008 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2009 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2010 ++i; /* the cursor should not jump
2011 * to the main body if there
2017 LyXParagraph * LyXParagraph::DepthHook(int deth)
2019 LyXParagraph * newpar = this;
2024 newpar = newpar->FirstPhysicalPar()->Previous();
2025 } while (newpar && newpar->GetDepth() > deth
2026 && newpar->footnoteflag == footnoteflag);
2029 if (Previous() || GetDepth())
2030 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2034 return newpar->FirstPhysicalPar();
2038 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2040 LyXParagraph const * newpar = this;
2045 newpar = newpar->FirstPhysicalPar()->Previous();
2046 } while (newpar && newpar->GetDepth() > deth
2047 && newpar->footnoteflag == footnoteflag);
2050 if (Previous() || GetDepth())
2051 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2055 return newpar->FirstPhysicalPar();
2059 int LyXParagraph::AutoDeleteInsets()
2062 InsetList::size_type index = 0;
2063 while (index < insetlist.size()) {
2064 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2065 Erase(insetlist[index].pos);
2066 // Erase() calls to insetlist.erase(&insetlist[index])
2067 // so index shouldn't be increased.
2076 LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2078 InsetList::iterator it = lower_bound(insetlist.begin(),
2081 return inset_iterator(it);
2085 // returns -1 if inset not found
2086 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2089 // We could use lower_bound here too, we just need to add
2090 // the approp. operator() to matchIT (and change the name
2091 // of that struct). Code would then be:
2092 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2094 // inset, matchIT());
2095 // if ((*cit).inset == inset) {
2096 // return (*cit).pos;
2098 for (InsetList::const_iterator cit = insetlist.begin();
2099 cit != insetlist.end(); ++cit) {
2100 if ((*cit).inset == inset) {
2104 // Think about footnotes.
2105 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2106 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2108 NextAfterFootnote()->GetPositionOfInset(inset);
2110 return text.size() + 1 + further;
2116 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2117 BufferParams const & bparams,
2118 ostream & os, TexRow & texrow,
2121 TexRow & foot_texrow,
2124 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2125 LyXLayout const & style =
2126 textclasslist.Style(bparams.textclass,
2129 bool further_blank_line = false;
2131 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2133 if (start_of_appendix) {
2134 os << "\\appendix\n";
2138 if (!spacing.isDefault()
2139 && (!Previous() || !Previous()->HasSameLayout(this))) {
2140 os << spacing.writeEnvirBegin() << "\n";
2144 if (tex_code_break_column && style.isCommand()){
2149 if (pagebreak_top) {
2151 further_blank_line = true;
2153 if (added_space_top.kind() != VSpace::NONE) {
2154 os << added_space_top.asLatexCommand(bparams);
2155 further_blank_line = true;
2159 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2160 << "\\vspace{-1\\parskip}";
2161 further_blank_line = true;
2164 if (further_blank_line){
2169 Language const * language = getParLanguage(bparams);
2170 Language const * doc_language = bparams.language_info;
2171 if (language != doc_language &&
2172 (!previous || previous->getParLanguage(bparams) != language)) {
2173 os << subst(lyxrc.language_command_begin, "$$lang",
2179 switch (style.latextype) {
2182 << style.latexname()
2183 << style.latexparam();
2185 case LATEX_ITEM_ENVIRONMENT:
2187 bibkey->Latex(buf, os, false, false);
2191 case LATEX_LIST_ENVIRONMENT:
2198 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2201 // Spit out footnotes
2202 LyXParagraph * par = next;
2203 if (lyxrc.rtl_support) {
2204 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2205 && next->footnoteflag != footnoteflag) {
2206 LyXParagraph * p = 0;
2207 bool is_rtl = (size() > 0)
2208 ? GetFontSettings(bparams,
2209 size()-1).isRightToLeft()
2210 : language->RightToLeft();
2211 if ( (p = NextAfterFootnote()) != 0 &&
2213 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2214 is_rtl = getParLanguage(bparams)->RightToLeft();
2215 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2216 && par->footnoteflag != footnoteflag) {
2217 par = par->TeXFootnote(buf, bparams,
2219 foot_texrow, foot_count,
2221 par->SimpleTeXOnePar(buf, bparams,
2222 os, texrow, moving_arg);
2223 is_rtl = (par->size() > 0)
2224 ? par->GetFontSettings(bparams,
2225 par->size()-1).isRightToLeft()
2226 : language->RightToLeft();
2228 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2229 (p = par->NextAfterFootnote()) != 0 &&
2231 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2232 is_rtl = language->RightToLeft();
2237 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2238 && par->footnoteflag != footnoteflag) {
2239 par = par->TeXFootnote(buf, bparams,
2241 foot, foot_texrow, foot_count,
2243 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2249 // Make sure that \\par is done with the font of the last
2250 // character if this has another size as the default.
2251 // This is necessary because LaTeX (and LyX on the screen)
2252 // calculates the space between the baselines according
2253 // to this font. (Matthias)
2254 LyXFont font = getFont(bparams, Last() - 1);
2256 if (style.resfont.size() != font.size()) {
2262 } else if (textclasslist.Style(bparams.textclass,
2263 GetLayout()).isCommand()) {
2264 if (style.resfont.size() != font.size()) {
2270 } else if (style.resfont.size() != font.size()){
2271 os << "{\\" << font.latexSize() << " \\par}";
2274 if (language != doc_language &&
2276 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2277 || par->getParLanguage(bparams) != language)) {
2279 << subst(lyxrc.language_command_end, "$$lang",
2280 doc_language->lang());
2283 switch (style.latextype) {
2284 case LATEX_ITEM_ENVIRONMENT:
2285 case LATEX_LIST_ENVIRONMENT:
2286 if (par && (depth < par->depth)) {
2291 case LATEX_ENVIRONMENT:
2292 // if its the last paragraph of the current environment
2293 // skip it otherwise fall through
2295 && (par->layout != layout
2296 || par->depth != depth
2297 || par->pextra_type != pextra_type))
2300 // we don't need it for the last paragraph!!!
2301 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2302 && footnotekind != LyXParagraph::FOOTNOTE
2303 && footnotekind != LyXParagraph::MARGIN
2307 // don't insert this if we would be adding it
2308 // before or after a table in a float. This
2309 // little trick is needed in order to allow
2310 // use of tables in \subfigures or \subtables.
2316 further_blank_line = false;
2318 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2319 further_blank_line = true;
2322 if (added_space_bottom.kind() != VSpace::NONE) {
2323 os << added_space_bottom.asLatexCommand(bparams);
2324 further_blank_line = true;
2327 if (pagebreak_bottom) {
2329 further_blank_line = true;
2332 if (further_blank_line){
2337 if (!spacing.isDefault()
2338 && (!par || !par->HasSameLayout(this))) {
2339 os << spacing.writeEnvirEnd() << "\n";
2343 // we don't need it for the last paragraph!!!
2344 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2345 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2350 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2355 // This one spits out the text of the paragraph
2356 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2357 BufferParams const & bparams,
2358 ostream & os, TexRow & texrow,
2361 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2365 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2368 bool return_value = false;
2370 LyXLayout const & style =
2371 textclasslist.Style(bparams.textclass,
2373 LyXFont basefont, last_font;
2375 // Maybe we have to create a optional argument.
2376 size_type main_body;
2377 if (style.labeltype != LABEL_MANUAL)
2380 main_body = BeginningOfMainBody();
2382 if (main_body > 0) {
2384 basefont = getFont(bparams, -2); // Get label font
2386 basefont = getFont(bparams, -1); // Get layout font
2394 if (style.isCommand()) {
2397 } else if (align != LYX_ALIGN_LAYOUT) {
2400 return_value = true;
2404 moving_arg |= style.needprotect;
2406 // Which font is currently active?
2407 LyXFont running_font(basefont);
2408 // Do we have an open font change?
2409 bool open_font = false;
2411 texrow.start(this, 0);
2413 for (size_type i = 0; i < size(); ++i) {
2415 // First char in paragraph or after label?
2416 if (i == main_body && !IsDummy()) {
2417 if (main_body > 0) {
2419 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2422 basefont = getFont(bparams, -1); // Now use the layout font
2423 running_font = basefont;
2427 if (style.isCommand()) {
2430 } else if (align != LYX_ALIGN_LAYOUT) {
2433 return_value = true;
2437 os << "\\noindent ";
2441 case LYX_ALIGN_NONE:
2442 case LYX_ALIGN_BLOCK:
2443 case LYX_ALIGN_LAYOUT:
2444 case LYX_ALIGN_SPECIAL:
2446 case LYX_ALIGN_LEFT:
2447 if (getParLanguage(bparams)->lang() != "hebrew") {
2448 os << "\\raggedright ";
2451 os << "\\raggedleft ";
2455 case LYX_ALIGN_RIGHT:
2456 if (getParLanguage(bparams)->lang() != "hebrew") {
2457 os << "\\raggedleft ";
2460 os << "\\raggedright ";
2464 case LYX_ALIGN_CENTER:
2465 os << "\\centering ";
2473 // Fully instantiated font
2474 LyXFont font = getFont(bparams, i);
2475 LyXParagraph * p = 0;
2476 if (i == 0 && previous &&
2477 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2478 (p = PreviousBeforeFootnote()) != 0)
2479 last_font = p->getFont(bparams, p->size()-1);
2481 last_font = running_font;
2483 // Spaces at end of font change are simulated to be
2484 // outside font change, i.e. we write "\textXX{text} "
2485 // rather than "\textXX{text }". (Asger)
2486 if (open_font && c == ' ' && i <= size() - 2
2487 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2488 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2489 font = getFont(bparams, i + 1);
2491 // We end font definition before blanks
2492 if (!font.equalExceptLatex(running_font) && open_font) {
2493 column += running_font.latexWriteEndChanges(os,
2495 (i == main_body-1) ? basefont : font);
2496 running_font = basefont;
2500 // Blanks are printed before start of fontswitch
2502 // Do not print the separation of the optional argument
2503 if (i != main_body - 1) {
2504 SimpleTeXBlanks(os, texrow, i,
2505 column, font, style);
2509 // Do we need to change font?
2510 if (!font.equalExceptLatex(running_font)
2511 && i != main_body-1) {
2512 column += font.latexWriteStartChanges(os, basefont,
2514 running_font = font;
2518 if (c == LyXParagraph::META_NEWLINE) {
2519 // newlines are handled differently here than
2520 // the default in SimpleTeXSpecialChars().
2521 if (!style.newline_allowed
2522 || font.latex() == LyXFont::ON) {
2526 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2529 basefont = getFont(bparams, -1);
2530 running_font = basefont;
2531 if (font.family() ==
2532 LyXFont::TYPEWRITER_FAMILY) {
2540 texrow.start(this, i + 1);
2543 SimpleTeXSpecialChars(buf, bparams,
2544 os, texrow, moving_arg,
2545 font, running_font, basefont,
2546 open_font, style, i, column, c);
2550 // If we have an open font definition, we have to close it
2552 LyXParagraph * p = 0;
2553 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2554 && (p = NextAfterFootnote()) != 0)
2555 running_font.latexWriteEndChanges(os, basefont,
2556 p->getFont(bparams, 0));
2558 running_font.latexWriteEndChanges(os, basefont, basefont);
2561 // Needed if there is an optional argument but no contents.
2562 if (main_body > 0 && main_body == size()) {
2564 return_value = false;
2567 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2568 return return_value;
2572 // This one spits out the text of a table paragraph
2573 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2574 BufferParams const & bparams,
2575 ostream & os, TexRow & texrow)
2577 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2579 bool return_value = false;
2581 LyXLayout const & style =
2582 textclasslist.Style(bparams.textclass, GetLayout());
2585 if (!IsDummy()) { // it is dummy if it is in a float!!!
2586 if (style.isCommand()) {
2589 } else if (align != LYX_ALIGN_LAYOUT) {
2592 return_value = true;
2595 os << "\\noindent ";
2599 case LYX_ALIGN_NONE:
2600 case LYX_ALIGN_BLOCK:
2601 case LYX_ALIGN_LAYOUT:
2602 case LYX_ALIGN_SPECIAL: break;
2603 case LYX_ALIGN_LEFT:
2604 os << "\\raggedright ";
2607 case LYX_ALIGN_RIGHT:
2608 os << "\\raggedleft ";
2611 case LYX_ALIGN_CENTER:
2612 os << "\\centering ";
2618 LyXFont basefont = getFont(bparams, -1); // Get layout font
2619 // Which font is currently active?
2620 LyXFont running_font = basefont;
2622 // Do we have an open font change?
2623 bool open_font = false;
2624 int current_cell_number = -1;
2625 int tmp = table->TexEndOfCell(os, current_cell_number);
2626 for (; tmp > 0 ; --tmp)
2629 texrow.start(this, 0);
2631 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2632 bool first_in_cell = true;
2634 for (size_type i = 0; i < size(); ++i) {
2635 char c = GetChar(i);
2636 if (table->IsContRow(current_cell_number + 1)) {
2637 if (c == LyXParagraph::META_NEWLINE)
2638 ++current_cell_number;
2643 if (first_in_cell && is_rtl) {
2646 first_in_cell = false;
2649 // Fully instantiated font
2650 LyXFont font = getFont(bparams, i);
2651 last_font = running_font;
2653 // Spaces at end of font change are simulated to be
2654 // outside font change.
2655 // i.e. we write "\textXX{text} " rather than
2656 // "\textXX{text }". (Asger)
2657 if (open_font && c == ' ' && i <= size() - 2
2658 && getFont(bparams, i + 1) != running_font
2659 && getFont(bparams, i + 1) != font) {
2660 font = getFont(bparams, i + 1);
2663 // We end font definition before blanks
2664 if (font != running_font && open_font) {
2665 column += running_font.latexWriteEndChanges(os,
2668 running_font = basefont;
2671 // Blanks are printed before start of fontswitch
2673 SimpleTeXBlanks(os, texrow, i, column, font, style);
2675 // Do we need to change font?
2676 if (font != running_font) {
2677 column += font.latexWriteStartChanges(os, basefont,
2679 running_font = font;
2682 // Do we need to turn on LaTeX mode?
2683 if (font.latex() != running_font.latex()) {
2684 if (font.latex() == LyXFont::ON
2685 && style.needprotect) {
2690 if (c == LyXParagraph::META_NEWLINE) {
2691 // special case for inside a table
2692 // different from default case in
2693 // SimpleTeXSpecialChars()
2695 column += running_font
2696 .latexWriteEndChanges(os, basefont,
2700 basefont = getFont(bparams, -1);
2701 running_font = basefont;
2702 ++current_cell_number;
2703 if (table->CellHasContRow(current_cell_number) >= 0) {
2704 TeXContTableRows(buf, bparams, os, i + 1,
2705 current_cell_number,
2708 if (is_rtl && !first_in_cell) {
2710 first_in_cell = true;
2713 // if this cell follow only ContRows till end don't
2714 // put the EndOfCell because it is put after the
2716 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2717 --current_cell_number;
2720 int tmp = table->TexEndOfCell(os,
2721 current_cell_number);
2724 } else if (tmp < 0) {
2730 texrow.start(this, i + 1);
2732 SimpleTeXSpecialChars(buf, bparams,
2734 font, running_font, basefont,
2735 open_font, style, i, column, c);
2739 // If we have an open font definition, we have to close it
2741 running_font.latexWriteEndChanges(os, basefont, basefont);
2743 ++current_cell_number;
2744 if (is_rtl && !first_in_cell)
2746 tmp = table->TexEndOfCell(os, current_cell_number);
2747 for (; tmp > 0; --tmp)
2749 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2750 return return_value;
2754 // This one spits out the text off ContRows in tables
2755 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2756 BufferParams const & bparams,
2758 LyXParagraph::size_type i,
2759 int current_cell_number,
2760 int & column, TexRow & texrow)
2762 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2766 bool return_value = false;
2767 LyXLayout const & style =
2768 textclasslist.Style(bparams.textclass,
2770 LyXFont basefont = getFont(bparams, -1); // Get layout font
2772 // Which font is currently active?
2773 LyXFont running_font = basefont;
2774 // Do we have an open font change?
2775 bool open_font = false;
2777 size_type lastpos = i;
2778 int cell = table->CellHasContRow(current_cell_number);
2779 ++current_cell_number;
2782 // first find the right position
2784 for (; (i < size()) && (current_cell_number<cell); ++i) {
2786 if (c == LyXParagraph::META_NEWLINE)
2787 ++current_cell_number;
2791 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2795 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2800 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2804 // Fully instantiated font
2805 LyXFont font = getFont(bparams, i);
2806 last_font = running_font;
2808 // Spaces at end of font change are simulated to
2809 // be outside font change. i.e. we write
2810 // "\textXX{text} " rather than "\textXX{text }".
2812 if (open_font && c == ' ' && i <= size() - 2
2813 && getFont(bparams, i + 1) != running_font
2814 && getFont(bparams, i + 1) != font) {
2815 font = getFont(bparams, i + 1);
2818 // We end font definition before blanks
2819 if (font != running_font && open_font) {
2820 column += running_font.latexWriteEndChanges(os, basefont, font);
2821 running_font = basefont;
2824 // Blanks are printed before start of fontswitch
2826 SimpleTeXBlanks(os, texrow, i,
2827 column, font, style);
2829 // Do we need to change font?
2830 if (font != running_font) {
2832 font.latexWriteStartChanges(os,
2835 running_font = font;
2838 // Do we need to turn on LaTeX mode?
2839 if (font.latex() != running_font.latex()) {
2840 if (font.latex() == LyXFont::ON
2841 && style.needprotect) {
2846 SimpleTeXSpecialChars(buf, bparams,
2847 os, texrow, false, font,
2848 running_font, basefont,
2849 open_font, style, i, column, c);
2851 // If we have an open font definition, we have to close it
2853 running_font.latexWriteEndChanges(os, basefont,
2857 basefont = getFont(bparams, -1);
2858 running_font = basefont;
2859 cell = table->CellHasContRow(current_cell_number);
2861 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2862 return return_value;
2866 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2868 bool retval = false;
2870 case LyXParagraph::META_HFILL:
2871 sgml_string.erase();
2873 case LyXParagraph::META_NEWLINE:
2877 sgml_string = "&";
2880 sgml_string = "<";
2883 sgml_string = ">";
2886 sgml_string = "$";
2889 sgml_string = "#";
2892 sgml_string = "%";
2895 sgml_string = "[";
2898 sgml_string = "]";
2901 sgml_string = "{";
2904 sgml_string = "}";
2907 sgml_string = "˜";
2910 sgml_string = """;
2913 sgml_string = "\";
2919 case '\0': // Ignore :-)
2920 sgml_string.erase();
2930 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
2931 ostream & os, string & extra,
2932 int & desc_on, int depth)
2934 BufferParams const & bparams = buffer->params;
2936 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2938 LyXFont font1, font2;
2941 size_type main_body;
2942 bool emph_flag = false;
2944 LyXLayout const & style =
2945 textclasslist.Style(bparams.textclass,
2948 if (style.labeltype != LABEL_MANUAL)
2951 main_body = BeginningOfMainBody();
2953 // Gets paragraph main font.
2955 font1 = style.labelfont;
2959 int char_line_count = depth;
2960 os << newlineAndDepth(depth);
2961 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2962 os << "<INFORMALTABLE>"
2963 << newlineAndDepth(++depth);
2965 int current_cell_number = -1;
2966 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2968 // Parsing main loop.
2969 for (size_type i = 0; i < size(); ++i) {
2971 if (table->IsContRow(current_cell_number+1)) {
2972 if (c == LyXParagraph::META_NEWLINE)
2973 ++current_cell_number;
2978 // Fully instantiated font
2979 font2 = getFont(bparams, i);
2981 // Handle <emphasis> tag.
2982 if (font1.emph() != font2.emph() && i) {
2983 if (font2.emph() == LyXFont::ON) {
2986 } else if (emph_flag) {
2987 os << "</emphasis>";
2991 if (c == LyXParagraph::META_NEWLINE) {
2992 // We have only to control for emphasis open here!
2994 os << "</emphasis>";
2997 font1 = font2 = getFont(bparams, -1);
2998 ++current_cell_number;
2999 if (table->CellHasContRow(current_cell_number) >= 0) {
3000 DocBookContTableRows(buffer,
3001 os, extra, desc_on, i + 1,
3002 current_cell_number,
3005 // if this cell follow only ContRows till end don't
3006 // put the EndOfCell because it is put after the
3008 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3009 --current_cell_number;
3012 tmp = table->DocBookEndOfCell(os,
3013 current_cell_number,
3018 } else if (c == LyXParagraph::META_INSET) {
3019 inset = GetInset(i);
3021 std::ostringstream ost;
3022 inset->DocBook(buffer, ost);
3023 string tmp_out = ost.str().c_str();
3026 inset->DocBook(buffer, ost);
3028 char * ctmp = ost.str();
3029 string tmp_out(ctmp);
3033 // This code needs some explanation:
3034 // Two insets are treated specially
3035 // label if it is the first element in a
3036 // command paragraph
3038 // graphics inside tables or figure floats
3040 // title (the equivalente in latex for this
3042 // and title should come first
3045 if(desc_on != 3 || i != 0) {
3046 if(tmp_out[0] == '@') {
3048 extra += frontStrip(tmp_out,
3051 os << frontStrip(tmp_out,
3056 } else if (font2.latex() == LyXFont::ON) {
3057 // "TeX"-Mode on == > SGML-Mode on.
3063 if (linuxDocConvertChar(c, sgml_string)
3064 && !style.free_spacing) {
3065 // in freespacing mode, spaces are
3066 // non-breaking characters
3071 << "</term><listitem><para>";
3083 // Needed if there is an optional argument but no contents.
3084 if (main_body > 0 && main_body == size()) {
3089 os << "</emphasis>";
3092 ++current_cell_number;
3093 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3094 // Resets description flag correctly.
3097 // <term> not closed...
3101 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3102 os << "</INFORMALTABLE>";
3104 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3109 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3110 ostream & os, string & extra,
3112 LyXParagraph::size_type i,
3113 int current_cell_number, int &column)
3118 BufferParams const & bparams = buffer->params;
3120 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3125 //string emph = "emphasis";
3126 bool emph_flag = false;
3127 int char_line_count = 0;
3129 LyXLayout const & style =
3130 textclasslist.Style(bparams.textclass,
3133 size_type main_body;
3134 if (style.labeltype != LABEL_MANUAL)
3137 main_body = BeginningOfMainBody();
3139 // Gets paragraph main font.
3142 font1 = style.labelfont;
3146 size_type lastpos = i;
3147 int cell = table->CellHasContRow(current_cell_number);
3148 ++current_cell_number;
3150 // first find the right position
3152 for (; i < size() && current_cell_number < cell; ++i) {
3154 if (c == LyXParagraph::META_NEWLINE)
3155 ++current_cell_number;
3159 // I don't know how to handle this so I comment it
3160 // for the moment (Jug)
3161 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3162 // file += " \\\\\n";
3165 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3170 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3174 // Fully instantiated font
3175 font2 = getFont(bparams, i);
3177 // Handle <emphasis> tag.
3178 if (font1.emph() != font2.emph() && i) {
3179 if (font2.emph() == LyXFont::ON) {
3182 } else if (emph_flag) {
3183 os << "</emphasis>";
3187 if (c == LyXParagraph::META_INSET) {
3188 inset = GetInset(i);
3190 std::ostringstream ost;
3191 inset->DocBook(buffer, ost);
3192 string tmp_out = ost.str().c_str();
3195 inset->DocBook(buffer, ost);
3197 char * ctmp = ost.str();
3198 string tmp_out(ctmp);
3202 // This code needs some explanation:
3203 // Two insets are treated specially
3204 // label if it is the first element in a
3205 // command paragraph
3207 // graphics inside tables or figure floats
3208 // can't go on title (the equivalente in
3209 // latex for this case is caption and title
3210 // should come first
3213 if(desc_on != 3 || i != 0) {
3214 if(tmp_out[0] == '@') {
3216 extra += frontStrip(tmp_out, '@');
3218 os << frontStrip(tmp_out, '@');
3222 } else if (font2.latex() == LyXFont::ON) {
3223 // "TeX"-Mode on == > SGML-Mode on.
3229 if (linuxDocConvertChar(c, sgml_string)
3230 && !style.free_spacing) {
3231 // in freespacing mode, spaces are
3232 // non-breaking characters
3237 << "</term><listitem><para>";
3247 // we have only to control for emphasis open here!
3249 os << "</emphasis>";
3252 font1 = font2 = getFont(bparams, -1);
3253 cell = table->CellHasContRow(current_cell_number);
3255 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3259 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3260 LyXParagraph::size_type const i,
3261 int & column, LyXFont const & font,
3262 LyXLayout const & style)
3264 if (column > tex_code_break_column
3266 && GetChar(i - 1) != ' '
3268 // In LaTeX mode, we don't want to
3269 // break lines since some commands
3271 && ! (font.latex() == LyXFont::ON)
3272 // same in FreeSpacing mode
3273 && !style.free_spacing
3274 // In typewriter mode, we want to avoid
3275 // ! . ? : at the end of a line
3276 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3277 && (GetChar(i-1) == '.'
3278 || GetChar(i-1) == '?'
3279 || GetChar(i-1) == ':'
3280 || GetChar(i-1) == '!'))) {
3281 if (tex_code_break_column == 0) {
3282 // in batchmode we need LaTeX to still
3283 // see it as a space not as an extra '\n'
3289 texrow.start(this, i + 1);
3291 } else if (font.latex() == LyXFont::OFF) {
3292 if (style.free_spacing) {
3301 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3302 BufferParams const & bparams,
3303 ostream & os, TexRow & texrow,
3306 LyXFont & running_font,
3309 LyXLayout const & style,
3310 LyXParagraph::size_type & i,
3311 int & column, char const c)
3313 // Two major modes: LaTeX or plain
3314 // Handle here those cases common to both modes
3315 // and then split to handle the two modes separately.
3317 case LyXParagraph::META_INSET: {
3318 Inset * inset = GetInset(i);
3321 int len = os.tellp();
3322 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3323 || inset->LyxCode() == Inset::MATH_CODE
3324 || inset->LyxCode() == Inset::URL_CODE)
3325 && running_font.isRightToLeft()) {
3330 int tmp = inset->Latex(buf, os, moving_arg,
3331 style.free_spacing);
3339 column += os.tellp() - len;
3348 case LyXParagraph::META_NEWLINE:
3350 column += running_font.latexWriteEndChanges(os,
3355 basefont = getFont(bparams, -1);
3356 running_font = basefont;
3359 case LyXParagraph::META_HFILL:
3365 // And now for the special cases within each mode
3366 // Are we in LaTeX mode?
3367 if (font.latex() == LyXFont::ON) {
3368 // at present we only have one option
3369 // but I'll leave it as a switch statement
3370 // so its simpler to extend. (ARRae)
3373 // make sure that we will not print
3374 // error generating chars to the tex
3375 // file. This test would not be needed
3376 // if it were done in the buffer
3384 // Plain mode (i.e. not LaTeX)
3387 os << "\\textbackslash{}";
3391 case '°': case '±': case '²': case '³':
3392 case '×': case '÷': case '¹': case 'ª':
3393 case 'º': case '¬': case 'µ':
3394 if (bparams.inputenc == "latin1") {
3395 os << "\\ensuremath{"
3404 case '|': case '<': case '>':
3405 // In T1 encoding, these characters exist
3406 if (lyxrc.fontenc == "T1") {
3408 //... but we should avoid ligatures
3409 if ((c == '>' || c == '<')
3411 && GetChar(i + 1) == c){
3412 os << "\\textcompwordmark{}";
3417 // Typewriter font also has them
3418 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3422 // Otherwise, we use what LaTeX
3426 os << "\\textless{}";
3430 os << "\\textgreater{}";
3434 os << "\\textbar{}";
3440 case '-': // "--" in Typewriter mode -> "-{}-"
3442 && GetChar(i + 1) == '-'
3443 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3452 os << "\\char`\\\"{}";
3457 if (bparams.inputenc == "default") {
3466 case '%': case '#': case '{':
3473 os << "\\textasciitilde{}";
3478 os << "\\textasciicircum{}";
3482 case '*': case '[': case ']':
3483 // avoid being mistaken for optional arguments
3484 os << '{' << c << '}';
3489 // Blanks are printed before font switching.
3490 // Sure? I am not! (try nice-latex)
3491 // I am sure it's correct. LyX might be smarter
3492 // in the future, but for now, nothing wrong is
3497 /* idea for labels --- begin*/
3501 && font.family() != LyXFont::TYPEWRITER_FAMILY
3502 && GetChar(i + 1) == 'y'
3503 && GetChar(i + 2) == 'X') {
3511 && font.family() != LyXFont::TYPEWRITER_FAMILY
3512 && GetChar(i + 1) == 'e'
3513 && GetChar(i + 2) == 'X') {
3518 // Check for "LaTeX2e"
3521 && font.family() != LyXFont::TYPEWRITER_FAMILY
3522 && GetChar(i + 1) == 'a'
3523 && GetChar(i + 2) == 'T'
3524 && GetChar(i + 3) == 'e'
3525 && GetChar(i + 4) == 'X'
3526 && GetChar(i + 5) == '2'
3527 && GetChar(i + 6) == 'e') {
3532 // Check for "LaTeX"
3535 && font.family() != LyXFont::TYPEWRITER_FAMILY
3536 && GetChar(i + 1) == 'a'
3537 && GetChar(i + 2) == 'T'
3538 && GetChar(i + 3) == 'e'
3539 && GetChar(i + 4) == 'X') {
3543 /* idea for labels --- end*/
3544 } else if (c != '\0') {
3554 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3555 BufferParams const & bparams,
3556 ostream & os, TexRow & texrow,
3558 TexRow & foot_texrow,
3561 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3562 LyXParagraph * par = this;
3565 (par->depth == depth) &&
3566 (par->footnoteflag == footnoteflag)) {
3568 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3569 if (textclasslist.Style(bparams.textclass,
3570 par->layout).isEnvironment()
3571 || par->pextra_type != PEXTRA_NONE) {
3572 par = par->TeXEnvironment(buf, bparams,
3577 par = par->TeXOnePar(buf, bparams,
3583 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3589 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3590 BufferParams const & bparams,
3591 ostream & os, TexRow & texrow,
3593 TexRow & foot_texrow,
3596 bool eindent_open = false;
3597 bool foot_this_level = false;
3598 // flags when footnotetext should be appended to file.
3599 static bool minipage_open = false;
3600 static int minipage_open_depth = 0;
3601 char par_sep = bparams.paragraph_separation;
3603 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3605 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3607 LyXLayout const & style =
3608 textclasslist.Style(bparams.textclass,
3611 if (pextra_type == PEXTRA_INDENT) {
3612 if (!pextra_width.empty()) {
3613 os << "\\begin{LyXParagraphIndent}{"
3614 << pextra_width << "}\n";
3616 //float ib = atof(pextra_widthp.c_str())/100;
3617 // string can't handle floats at present (971109)
3618 // so I'll do a conversion by hand knowing that
3619 // the limits are 0.0 to 1.0. ARRae.
3620 os << "\\begin{LyXParagraphIndent}{";
3621 switch (pextra_widthp.length()) {
3633 os << "\\columnwidth}\n";
3636 eindent_open = true;
3638 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3639 if (pextra_hfill && Previous() &&
3640 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3641 os << "\\hfill{}\n";
3644 if (par_sep == BufferParams::PARSEP_INDENT) {
3645 os << "{\\setlength\\parindent{0pt}\n";
3648 os << "\\begin{minipage}";
3649 switch(pextra_alignment) {
3650 case MINIPAGE_ALIGN_TOP:
3653 case MINIPAGE_ALIGN_MIDDLE:
3656 case MINIPAGE_ALIGN_BOTTOM:
3660 if (!pextra_width.empty()) {
3661 os << '{' << pextra_width << "}\n";
3663 //float ib = atof(par->pextra_width.c_str())/100;
3664 // string can't handle floats at present
3665 // so I'll do a conversion by hand knowing that
3666 // the limits are 0.0 to 1.0. ARRae.
3668 switch (pextra_widthp.length()) {
3680 os << "\\columnwidth}\n";
3683 if (par_sep == BufferParams::PARSEP_INDENT) {
3684 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3687 minipage_open = true;
3688 minipage_open_depth = depth;
3691 #ifdef WITH_WARNINGS
3692 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3693 //I disabled it because it breaks when lists span on several
3696 if (style.isEnvironment()){
3697 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3698 #ifdef FANCY_FOOTNOTE_CODE
3699 if (foot_count < 0) {
3700 // flag that footnote[mark][text] should be
3701 // used for any footnotes from now on
3703 foot_this_level = true;
3706 os << "\\begin{" << style.latexname() << "}{"
3707 << labelwidthstring << "}\n";
3708 } else if (style.labeltype == LABEL_BIBLIO) {
3710 os << "\\begin{" << style.latexname() << "}{"
3711 << bibitemWidest(current_view->painter())
3713 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3714 #ifdef FANCY_FOOTNOTE_CODE
3715 if (foot_count < 0) {
3716 // flag that footnote[mark][text] should be
3717 // used for any footnotes from now on
3719 foot_this_level = true;
3722 os << "\\begin{" << style.latexname() << '}'
3723 << style.latexparam() << '\n';
3725 os << "\\begin{" << style.latexname() << '}'
3726 << style.latexparam() << '\n';
3729 LyXParagraph * par = this;
3731 par = par->TeXOnePar(buf, bparams,
3733 foot, foot_texrow, foot_count);
3735 if (minipage_open && par && !style.isEnvironment() &&
3736 (par->pextra_type == PEXTRA_MINIPAGE) &&
3737 par->pextra_start_minipage) {
3738 os << "\\end{minipage}\n";
3740 if (par_sep == BufferParams::PARSEP_INDENT) {
3744 minipage_open = false;
3746 if (par && par->depth > depth) {
3747 if (textclasslist.Style(bparams.textclass,
3748 par->layout).isParagraph()
3751 // How to handle this? (Lgb)
3752 //&& !suffixIs(os, "\n\n")
3754 // There should be at least one '\n' already
3755 // but we need there to be two for Standard
3756 // paragraphs that are depth-increment'ed to be
3757 // output correctly. However, tables can
3758 // also be paragraphs so don't adjust them.
3761 // Will it ever harm to have one '\n' too
3762 // many? i.e. that we sometimes will have
3763 // three in a row. (Lgb)
3767 par = par->TeXDeeper(buf, bparams, os, texrow,
3768 foot, foot_texrow, foot_count);
3770 if (par && par->layout == layout && par->depth == depth &&
3771 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3772 if (par->pextra_hfill && par->Previous() &&
3773 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3774 os << "\\hfill{}\n";
3777 if (par_sep == BufferParams::PARSEP_INDENT) {
3778 os << "{\\setlength\\parindent{0pt}\n";
3781 os << "\\begin{minipage}";
3782 switch(par->pextra_alignment) {
3783 case MINIPAGE_ALIGN_TOP:
3786 case MINIPAGE_ALIGN_MIDDLE:
3789 case MINIPAGE_ALIGN_BOTTOM:
3793 if (!par->pextra_width.empty()) {
3794 os << '{' << par->pextra_width << "}\n";
3796 //float ib = atof(par->pextra_widthp.c_str())/100;
3797 // string can't handle floats at present
3798 // so I'll do a conversion by hand knowing that
3799 // the limits are 0.0 to 1.0. ARRae.
3801 switch (par->pextra_widthp.length()) {
3806 os << "0." << par->pextra_widthp;
3809 os << "0.0" << par->pextra_widthp;
3811 os << "\\columnwidth}\n";
3814 if (par_sep == BufferParams::PARSEP_INDENT) {
3815 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3818 minipage_open = true;
3819 minipage_open_depth = par->depth;
3822 && par->layout == layout
3823 && par->depth == depth
3824 && par->pextra_type == pextra_type
3825 && par->footnoteflag == footnoteflag);
3827 if (style.isEnvironment()) {
3828 os << "\\end{" << style.latexname() << '}';
3829 // maybe this should go after the minipage closes?
3830 if (foot_this_level) {
3831 if (foot_count >= 1) {
3832 if (foot_count > 1) {
3833 os << "\\addtocounter{footnote}{-"
3838 texrow += foot_texrow;
3840 foot_texrow.reset();
3845 if (minipage_open && (minipage_open_depth == depth) &&
3846 (!par || par->pextra_start_minipage ||
3847 par->pextra_type != PEXTRA_MINIPAGE)) {
3848 os << "\\end{minipage}\n";
3850 if (par_sep == BufferParams::PARSEP_INDENT) {
3854 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3855 os << "\\medskip\n\n";
3859 minipage_open = false;
3862 os << "\\end{LyXParagraphIndent}\n";
3865 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3866 && par->pextra_hfill)) {
3870 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3871 return par; // ale970302
3876 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3877 BufferParams const & bparams,
3878 ostream & os, TexRow & texrow,
3879 ostream & foot, TexRow & foot_texrow,
3883 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3884 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3885 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3886 "No footnote!" << endl;
3888 LyXParagraph * par = this;
3889 LyXLayout const & style =
3890 textclasslist.Style(bparams.textclass,
3891 previous->GetLayout());
3893 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3894 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3895 "Float other than footnote in command"
3896 " with moving argument is illegal" << endl;
3899 if (footnotekind != LyXParagraph::FOOTNOTE
3900 && footnotekind != LyXParagraph::MARGIN
3903 // How to solve this?
3904 //&& !suffixIs(file, '\n')
3906 // we need to ensure that real floats like tables and figures
3907 // have their \begin{} on a new line otherwise we can get
3908 // incorrect results when using the endfloat.sty package
3909 // especially if two floats follow one another. ARRae 981022
3910 // NOTE: if the file is length 0 it must have just been
3911 // written out so we assume it ended with a '\n'
3913 // As far as I can see there is never any harm in writing
3914 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3919 bool moving_arg = false;
3920 bool need_closing = false;
3921 bool is_rtl = isRightToLeftPar(bparams);
3923 if (is_rtl != parent_is_rtl) {
3928 need_closing = true;
3931 //BufferParams * params = ¤t_view->buffer()->params;
3932 bool footer_in_body = true;
3933 switch (footnotekind) {
3934 case LyXParagraph::FOOTNOTE:
3935 if (style.intitle) {
3936 os << "\\thanks{\n";
3937 footer_in_body = false;
3940 if (foot_count == -1) {
3941 // we're at depth 0 so we can use:
3942 os << "\\footnote{%\n";
3943 footer_in_body = false;
3945 os << "\\footnotemark{}%\n";
3947 // we only need this when there are
3948 // multiple footnotes
3949 os << "\\stepcounter{footnote}";
3951 os << "\\footnotetext{%\n";
3952 foot_texrow.start(this, 0);
3953 foot_texrow.newline();
3958 case LyXParagraph::MARGIN:
3959 os << "\\marginpar{\n";
3961 case LyXParagraph::FIG:
3962 if (pextra_type == PEXTRA_FLOATFLT
3963 && (!pextra_width.empty()
3964 || !pextra_widthp.empty())) {
3965 if (!pextra_width.empty())
3966 os << "\\begin{floatingfigure}{"
3967 << pextra_width << "}\n";
3969 os << "\\begin{floatingfigure}{"
3970 << atoi(pextra_widthp.c_str())/100.0
3971 << "\\textwidth}\n";
3973 os << "\\begin{figure}";
3974 if (!bparams.float_placement.empty()) {
3975 os << '[' << bparams.float_placement << "]\n";
3981 case LyXParagraph::TAB:
3982 os << "\\begin{table}";
3983 if (!bparams.float_placement.empty()) {
3984 os << '[' << bparams.float_placement << "]\n";
3989 case LyXParagraph::WIDE_FIG:
3990 os << "\\begin{figure*}";
3991 if (!bparams.float_placement.empty()) {
3992 os << '[' << bparams.float_placement << "]\n";
3997 case LyXParagraph::WIDE_TAB:
3998 os << "\\begin{table*}";
3999 if (!bparams.float_placement.empty()) {
4000 os << '[' << bparams.float_placement << "]\n";
4005 case LyXParagraph::ALGORITHM:
4006 os << "\\begin{algorithm}\n";
4011 if (footnotekind != LyXParagraph::FOOTNOTE
4012 || !footer_in_body) {
4013 // Process text for all floats except footnotes in body
4015 LyXLayout const & style =
4017 .Style(bparams.textclass, par->layout);
4019 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4021 if (style.isEnvironment()
4022 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4023 // Allows the use of minipages within float
4024 // environments. Shouldn't be circular because
4025 // we don't support footnotes inside
4026 // floats (yet). ARRae
4027 par = par->TeXEnvironment(buf, bparams, os,
4032 par = par->TeXOnePar(buf, bparams,
4033 os, texrow, moving_arg,
4038 if (par && !par->IsDummy() && par->depth > depth) {
4039 par = par->TeXDeeper(buf, bparams, os, texrow,
4043 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4045 // process footnotes > depth 0 or in environments separately
4046 // NOTE: Currently don't support footnotes within footnotes
4047 // even though that is possible using the \footnotemark
4049 std::ostringstream dummy;
4053 TexRow dummy_texrow;
4054 int dummy_count = 0;
4056 LyXLayout const & style =
4058 .Style(bparams.textclass, par->layout);
4060 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4062 if (style.isEnvironment()
4063 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4064 // Allows the use of minipages within float
4065 // environments. Shouldn't be circular because
4066 // we don't support footnotes inside
4067 // floats (yet). ARRae
4068 par = par->TeXEnvironment(buf, bparams,
4070 dummy, dummy_texrow,
4073 par = par->TeXOnePar(buf, bparams,
4076 dummy, dummy_texrow,
4080 if (par && !par->IsDummy() && par->depth > depth) {
4081 par = par->TeXDeeper(buf, bparams,
4083 dummy, dummy_texrow,
4087 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4089 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4090 "Footnote in a Footnote -- not supported"
4093 #ifndef HAVE_OSTREAM
4094 delete [] dummy.str();
4098 switch (footnotekind) {
4099 case LyXParagraph::FOOTNOTE:
4100 if (footer_in_body) {
4101 // This helps tell which of the multiple
4102 // footnotetexts an error was in.
4104 foot_texrow.newline();
4109 case LyXParagraph::MARGIN:
4112 case LyXParagraph::FIG:
4113 if (pextra_type == PEXTRA_FLOATFLT
4114 && (!pextra_width.empty()
4115 || !pextra_widthp.empty()))
4116 os << "\\end{floatingfigure}";
4118 os << "\\end{figure}";
4120 case LyXParagraph::TAB:
4121 os << "\\end{table}";
4123 case LyXParagraph::WIDE_FIG:
4124 os << "\\end{figure*}";
4126 case LyXParagraph::WIDE_TAB:
4127 os << "\\end{table*}";
4129 case LyXParagraph::ALGORITHM:
4130 os << "\\end{algorithm}";
4137 if (footnotekind != LyXParagraph::FOOTNOTE
4138 && footnotekind != LyXParagraph::MARGIN) {
4139 // we need to ensure that real floats like tables and figures
4140 // have their \end{} on a line of their own otherwise we can
4141 // get incorrect results when using the endfloat.sty package.
4146 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4151 bool LyXParagraph::IsDummy() const
4153 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4154 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4158 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4159 int type, char const * width,
4160 char const * widthp)
4163 pextra_width = width;
4164 pextra_widthp = widthp;
4166 if (textclasslist.Style(bparams.textclass,
4167 layout).isEnvironment()) {
4172 while (par && (par->layout == layout)
4173 && (par->depth == depth)) {
4175 par = par->Previous();
4177 par = par->FirstPhysicalPar();
4178 while (par && par->depth > depth) {
4179 par = par->Previous();
4181 par = par->FirstPhysicalPar();
4185 while (par && (par->layout == layout)
4186 && (par->depth == depth)) {
4187 par->pextra_type = type;
4188 par->pextra_width = width;
4189 par->pextra_widthp = widthp;
4190 par = par->NextAfterFootnote();
4191 if (par && (par->depth > depth))
4192 par->SetPExtraType(bparams,
4193 type, width, widthp);
4194 while (par && ((par->depth > depth) || par->IsDummy()))
4195 par = par->NextAfterFootnote();
4201 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4203 if (pextra_type == PEXTRA_NONE)
4206 pextra_type = PEXTRA_NONE;
4207 pextra_width.erase();
4208 pextra_widthp.erase();
4210 if (textclasslist.Style(bparams.textclass,
4211 layout).isEnvironment()) {
4216 while (par && (par->layout == layout)
4217 && (par->depth == depth)) {
4219 par = par->Previous();
4221 par = par->FirstPhysicalPar();
4222 while (par && par->depth > depth) {
4223 par = par->Previous();
4225 par = par->FirstPhysicalPar();
4229 while (par && (par->layout == layout)
4230 && (par->depth == depth)) {
4231 par->pextra_type = PEXTRA_NONE;
4232 par->pextra_width.erase();
4233 par->pextra_widthp.erase();
4234 par = par->NextAfterFootnote();
4235 if (par && (par->depth > depth))
4236 par->UnsetPExtraType(bparams);
4237 while (par && ((par->depth > depth) || par->IsDummy()))
4238 par = par->NextAfterFootnote();
4244 bool LyXParagraph::IsHfill(size_type pos) const
4246 return IsHfillChar(GetChar(pos));
4250 bool LyXParagraph::IsInset(size_type pos) const
4252 return IsInsetChar(GetChar(pos));
4256 bool LyXParagraph::IsFloat(size_type pos) const
4258 return IsFloatChar(GetChar(pos));
4262 bool LyXParagraph::IsNewline(size_type pos) const
4264 return pos >= 0 && IsNewlineChar(GetChar(pos));
4268 bool LyXParagraph::IsSeparator(size_type pos) const
4270 return IsSeparatorChar(GetChar(pos));
4274 bool LyXParagraph::IsLineSeparator(size_type pos) const
4276 return IsLineSeparatorChar(GetChar(pos));
4280 bool LyXParagraph::IsKomma(size_type pos) const
4282 return IsKommaChar(GetChar(pos));
4286 /// Used by the spellchecker
4287 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4289 unsigned char c = GetChar(pos);
4290 if (IsLetterChar(c))
4292 // '\0' is not a letter, allthough every string contains "" (below)
4295 // We want to pass the ' and escape chars to ispell
4296 string extra = lyxrc.isp_esc_chars + '\'';
4300 return contains(extra, ch);
4304 bool LyXParagraph::IsWord(size_type pos ) const
4306 return IsWordChar(GetChar(pos)) ;
4311 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4314 return FirstPhysicalPar()->getParLanguage(bparams);
4315 else if (size() > 0)
4319 return GetFirstFontSettings().language();
4322 for (size_type pos = 0; pos < size(); ++pos)
4324 return GetFontSettings(bparams, pos).language();
4325 return GetFirstFontSettings().language();
4329 return previous->getParLanguage(bparams);
4331 return bparams.language_info;
4335 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4337 return lyxrc.rtl_support && !table
4338 && getParLanguage(bparams)->RightToLeft();
4342 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4343 Language const * from, Language const * to)
4345 for(size_type i = 0; i < size(); ++i) {
4346 LyXFont font = GetFontSettings(bparams, i);
4347 if (font.language() == from) {
4348 font.setLanguage(to);
4355 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4357 Language const * doc_language =
4358 bparams.language_info;
4359 for(size_type i = 0; i < size(); ++i) {
4360 LyXFont font = GetFontSettings(bparams, i);
4361 if (font.language() != doc_language)
4368 // Convert the paragraph to a string.
4369 // Used for building the table of contents
4370 string LyXParagraph::String(Buffer const * buffer, bool label)
4372 BufferParams const & bparams = buffer->params;
4374 if (label && !IsDummy() && !labelstring.empty())
4375 s += labelstring + ' ';
4376 string::size_type len = s.size();
4378 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4379 unsigned char c = GetChar(i);
4382 else if (c == META_INSET &&
4383 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4385 std::ostringstream ost;
4386 GetInset(i)->Ascii(buffer, ost);
4389 GetInset(i)->Ascii(buffer, ost);
4392 s += subst(ost.str(),'\n',' ');
4397 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4398 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4399 s += NextAfterFootnote()->String(buffer, false);
4404 if (isRightToLeftPar(bparams))
4405 reverse(s.begin() + len,s.end());
4411 string LyXParagraph::String(Buffer const * buffer,
4412 LyXParagraph::size_type beg,
4413 LyXParagraph::size_type end)
4420 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4422 if (cell >= table->NumberOfCellsInRow(actcell))
4430 if (beg == 0 && !IsDummy() && !labelstring.empty())
4431 s += labelstring + ' ';
4433 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4434 unsigned char c = GetChar(i);
4437 else if (c == META_INSET) {
4439 std::ostringstream ost;
4440 GetInset(i)->Ascii(buffer, ost);
4443 GetInset(i)->Ascii(buffer, ost);
4447 } else if (table && IsNewlineChar(c)) {
4448 if (cell >= table->NumberOfCellsInRow(actcell)) {
4459 //if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4460 // s += NextAfterFootnote()->String(false);
4466 void LyXParagraph::SetInsetOwner(Inset *i)
4469 for (InsetList::const_iterator cit = insetlist.begin();
4470 cit != insetlist.end(); ++cit) {
4472 (*cit).inset->setOwner(i);
4477 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4480 for (InsetList::const_iterator cit = insetlist.begin();
4481 cit != insetlist.end(); ++cit) {
4483 if ((*cit).inset->IsTextInset()) {
4484 static_cast<InsetText *>((*cit).inset)->