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))
467 if (minibuffer_char == LyXParagraph::META_INSET)
468 InsertInset(pos, minibuffer_inset, minibuffer_font);
470 InsertChar(pos, minibuffer_char, minibuffer_font);
478 void LyXParagraph::Clear()
483 pagebreak_top = false;
484 pagebreak_bottom = false;
486 added_space_top = VSpace(VSpace::NONE);
487 added_space_bottom = VSpace(VSpace::NONE);
488 spacing.set(Spacing::Default);
490 align = LYX_ALIGN_LAYOUT;
494 pextra_type = PEXTRA_NONE;
495 pextra_width.erase();
496 pextra_widthp.erase();
497 pextra_alignment = MINIPAGE_ALIGN_TOP;
498 pextra_hfill = false;
499 pextra_start_minipage = false;
502 labelwidthstring.erase();
506 start_of_appendix = false;
510 // the destructor removes the new paragraph from the list
511 LyXParagraph::~LyXParagraph()
514 previous->next = next;
516 next->previous = previous;
518 for (InsetList::iterator it = insetlist.begin();
519 it != insetlist.end(); ++it) {
523 /* table stuff -- begin*/
525 /* table stuff -- end*/
531 //lyxerr << "LyXParagraph::paragraph_id = "
532 // << LyXParagraph::paragraph_id << endl;
536 void LyXParagraph::Erase(LyXParagraph::size_type pos)
538 // > because last is the next unused position, and you can
539 // use it if you want
542 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
543 NextAfterFootnote()->Erase(pos - text.size() - 1);
546 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
547 "position does not exist." << endl;
550 if (pos < size()) { // last is free for insertation, but should be empty
551 // if it is an inset, delete the inset entry
552 if (text[pos] == LyXParagraph::META_INSET) {
554 InsetList::iterator it = lower_bound(insetlist.begin(),
557 if (it != insetlist.end() && (*it).pos == pos) {
562 text.erase(text.begin() + pos);
564 // Erase entries in the tables.
565 FontList::iterator it = lower_bound(fontlist.begin(),
568 if (it != fontlist.end() && (*it).pos == pos &&
570 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
571 // If it is a multi-character font
572 // entry, we just make it smaller
573 // (see update below), otherwise we
575 unsigned int i = it - fontlist.begin();
576 fontlist.erase(fontlist.begin() + i);
577 it = fontlist.begin() + i;
578 if (i > 0 && i < fontlist.size() &&
579 fontlist[i-1].font == fontlist[i].font) {
580 fontlist.erase(fontlist.begin() + i-1);
581 it = fontlist.begin() + i-1;
585 // Update all other entries.
586 for (; it != fontlist.end(); ++it)
589 // Update the inset table.
590 for (InsetList::iterator it = upper_bound(insetlist.begin(),
593 it != insetlist.end(); ++it)
596 lyxerr << "ERROR (LyXParagraph::Erase): "
597 "can't erase non-existant char." << endl;
602 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
604 LyXFont f(LyXFont::ALL_INHERIT);
605 InsertChar(pos, c, f);
609 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
610 char c, LyXFont const & font)
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)
645 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
648 LyXFont f(LyXFont::ALL_INHERIT);
649 InsertInset(pos, inset, f);
653 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
654 Inset * inset, LyXFont const & font)
658 // > because last is the next unused position, and you can
659 // use it if you want
663 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
665 ->InsertInset(pos - text.size() - 1,
669 lyxerr << "ERROR (LyXParagraph::InsertInset): "
670 "position does not exist: " << pos << endl;
674 InsertChar(pos, META_INSET, font);
675 Assert(text[pos] == META_INSET);
677 // Add a new entry in the inset table.
678 InsetList::iterator it = lower_bound(insetlist.begin(),
681 if (it != insetlist.end() && (*it).pos == pos)
682 lyxerr << "ERROR (LyXParagraph::InsertInset): "
683 "there is an inset in position: " << pos << endl;
685 insetlist.insert(it, InsetTable(pos, inset));
687 inset->setOwner(inset_owner);
691 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
694 return inset_owner->InsertInsetAllowed(inset);
699 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
704 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
705 return NextAfterFootnote()
706 ->GetInset(pos - text.size() - 1);
709 lyxerr << "ERROR (LyXParagraph::GetInset): "
710 "position does not exist: "
716 InsetList::iterator it = lower_bound(insetlist.begin(),
719 if (it != insetlist.end() && (*it).pos == pos)
722 lyxerr << "ERROR (LyXParagraph::GetInset): "
723 "Inset does not exist: " << pos << endl;
726 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
727 // Did this commenting out introduce a bug? So far I have not
728 // see any, please enlighten me. (Lgb)
729 // My guess is that since the inset does not exist, we might
730 // as well replace it with a space to prevent craches. (Asger)
735 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
740 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
741 return NextAfterFootnote()
742 ->GetInset(pos - text.size() - 1);
745 lyxerr << "ERROR (LyXParagraph::GetInset): "
746 "position does not exist: "
752 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
755 if (cit != insetlist.end() && (*cit).pos == pos)
758 lyxerr << "ERROR (LyXParagraph::GetInset): "
759 "Inset does not exist: " << pos << endl;
761 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
762 // Did this commenting out introduce a bug? So far I have not
763 // see any, please enlighten me. (Lgb)
764 // My guess is that since the inset does not exist, we might
765 // as well replace it with a space to prevent craches. (Asger)
770 // Gets uninstantiated font setting at position.
771 // Optimized after profiling. (Asger)
772 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
773 LyXParagraph::size_type pos) const
776 FontList::const_iterator cit = lower_bound(fontlist.begin(),
779 if (cit != fontlist.end())
782 // > because last is the next unused position, and you can
783 // use it if you want
784 else if (pos > size()) {
787 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
788 return NextAfterFootnote()
789 ->GetFontSettings(bparams,
790 pos - text.size() - 1);
793 // Why is it an error to ask for the font of a
794 // position that does not exist? Would it be
795 // enough for this to be enabled on debug?
796 // We want strict error checking, but it's ok to only
797 // have it when debugging. (Asger)
798 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
799 "position does not exist. "
800 << pos << " (" << static_cast<int>(pos)
802 } else if (pos > 0) {
803 return GetFontSettings(bparams, pos - 1);
804 } else // pos = size() = 0
805 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
807 return LyXFont(LyXFont::ALL_INHERIT);
810 // Gets uninstantiated font setting at position 0
811 LyXFont LyXParagraph::GetFirstFontSettings() const
814 if (!fontlist.empty())
815 return fontlist[0].font;
819 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
820 return NextAfterFootnote()->GetFirstFontSettings();
822 return LyXFont(LyXFont::ALL_INHERIT);
826 // Gets the fully instantiated font at a given position in a paragraph
827 // This is basically the same function as LyXText::GetFont() in text2.C.
828 // The difference is that this one is used for generating the LaTeX file,
829 // and thus cosmetic "improvements" are disallowed: This has to deliver
830 // the true picture of the buffer. (Asger)
831 // If position is -1, we get the layout font of the paragraph.
832 // If position is -2, we get the font of the manual label of the paragraph.
833 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
834 LyXParagraph::size_type pos) const
837 LyXLayout const & layout =
838 textclasslist.Style(bparams.textclass,
840 LyXParagraph::size_type main_body = 0;
841 if (layout.labeltype == LABEL_MANUAL)
842 main_body = BeginningOfMainBody();
847 layoutfont = layout.labelfont;
849 layoutfont = layout.font;
850 tmpfont = GetFontSettings(bparams, pos);
851 tmpfont.realize(layoutfont);
853 // process layoutfont for pos == -1 and labelfont for pos < -1
855 tmpfont = layout.font;
857 tmpfont = layout.labelfont;
858 tmpfont.setLanguage(getParLanguage(bparams));
861 // check for environment font information
862 char par_depth = GetDepth();
863 LyXParagraph const * par = this;
864 while (par && par_depth && !tmpfont.resolved()) {
865 par = par->DepthHook(par_depth - 1);
867 tmpfont.realize(textclasslist.
868 Style(bparams.textclass,
869 par->GetLayout()).font);
870 par_depth = par->GetDepth();
874 tmpfont.realize(textclasslist
875 .TextClass(bparams.textclass)
881 /// Returns the height of the highest font in range
883 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
884 LyXParagraph::size_type endpos) const
886 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
887 if (fontlist.empty())
890 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
893 if (end_it != fontlist.end())
896 for (FontList::const_iterator cit = lower_bound(fontlist.begin(),
898 startpos, matchFT());
899 cit != end_it; ++cit) {
900 LyXFont::FONT_SIZE size = (*cit).font.size();
901 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
908 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
915 // > because last is the next unused position, and you can
916 // use it if you want
917 else if (pos > size()) {
919 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
920 return NextAfterFootnote()
921 ->GetChar(pos - text.size() - 1);
925 lyxerr << "ERROR (LyXParagraph::GetChar): "
926 "position does not exist."
927 << pos << " (" << static_cast<int>(pos)
929 // Assert(false); // This triggers sometimes...
938 // We should have a footnote environment.
939 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
940 // Notice that LyX does request the
941 // last char from time to time. (Asger)
942 //lyxerr << "ERROR (LyXParagraph::GetChar): "
943 // "expected footnote." << endl;
946 switch (next->footnotekind) {
947 case LyXParagraph::FOOTNOTE:
948 return LyXParagraph::META_FOOTNOTE;
949 case LyXParagraph::MARGIN:
950 return LyXParagraph::META_MARGIN;
951 case LyXParagraph::FIG:
952 case LyXParagraph::WIDE_FIG:
953 return LyXParagraph::META_FIG;
954 case LyXParagraph::TAB:
955 case LyXParagraph::WIDE_TAB:
956 return LyXParagraph::META_TAB;
957 case LyXParagraph::ALGORITHM:
958 return LyXParagraph::META_ALGORITHM;
960 return '\0'; // to shut up gcc
966 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
973 // > because last is the next unused position, and you can
974 // use it if you want
975 else if (pos > size()) {
977 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
978 return NextAfterFootnote()
979 ->GetChar(pos - text.size() - 1);
983 lyxerr << "ERROR (LyXParagraph::GetChar const): "
984 "position does not exist."
985 << pos << " (" << static_cast<int>(pos)
993 // We should have a footnote environment.
994 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
995 // Notice that LyX does request the
996 // last char from time to time. (Asger)
997 //lyxerr << "ERROR (LyXParagraph::GetChar): "
998 // "expected footnote." << endl;
1001 switch (next->footnotekind) {
1002 case LyXParagraph::FOOTNOTE:
1003 return LyXParagraph::META_FOOTNOTE;
1004 case LyXParagraph::MARGIN:
1005 return LyXParagraph::META_MARGIN;
1006 case LyXParagraph::FIG:
1007 case LyXParagraph::WIDE_FIG:
1008 return LyXParagraph::META_FIG;
1009 case LyXParagraph::TAB:
1010 case LyXParagraph::WIDE_TAB:
1011 return LyXParagraph::META_TAB;
1012 case LyXParagraph::ALGORITHM:
1013 return LyXParagraph::META_ALGORITHM;
1015 return '\0'; // to shut up gcc
1021 // return an string of the current word, and the end of the word in lastpos.
1022 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1026 // the current word is defined as starting at the first character
1027 // from the immediate left of lastpospos which meets the definition
1028 // of IsLetter(), continuing to the last character to the right
1029 // of this meeting IsLetter.
1035 // move back until we have a letter
1037 //there's no real reason to have firstpos & lastpos as
1038 //separate variables as this is written, but maybe someon
1039 // will want to return firstpos in the future.
1041 //since someone might have typed a punctuation first
1042 int firstpos = lastpos;
1044 while ((firstpos >= 0) && !IsLetter(firstpos))
1047 // now find the beginning by looking for a nonletter
1049 while ((firstpos>= 0) && IsLetter(firstpos))
1052 // the above is now pointing to the preceeding non-letter
1056 // so copy characters into theword until we get a nonletter
1057 // note that this can easily exceed lastpos, wich means
1058 // that if used in the middle of a word, the whole word
1061 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1068 LyXParagraph::size_type LyXParagraph::Last() const
1071 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1072 return text.size() + NextAfterFootnote()->Last() + 1;
1073 // the 1 is the symbol
1081 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1083 // > because last is the next unused position, and you can
1084 // use it if you want
1088 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1089 return NextAfterFootnote()
1090 ->ParFromPos(pos - text.size() - 1);
1093 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1094 "position does not exist." << endl;
1101 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1103 // > because last is the next unused position, and you can
1104 // use it if you want
1108 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1109 return NextAfterFootnote()
1110 ->PositionInParFromPos(pos - text.size() - 1);
1114 "ERROR (LyXParagraph::PositionInParFromPos): "
1115 "position does not exist." << endl;
1123 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1124 LyXFont const & font)
1126 // > because last is the next unused position, and you can
1127 // use it if you want
1131 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1132 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1136 lyxerr << "ERROR (LyXParagraph::SetFont): "
1137 "position does not exist." << endl;
1142 // First, reduce font against layout/label font
1143 // Update: The SetCharFont() routine in text2.C already
1144 // reduces font, so we don't need to do that here. (Asger)
1145 // No need to simplify this because it will disappear
1146 // in a new kernel. (Asger)
1147 // Next search font table
1149 FontList::iterator it = lower_bound(fontlist.begin(),
1152 unsigned int i = it - fontlist.begin();
1153 bool notfound = it == fontlist.end();
1155 if (!notfound && fontlist[i].font == font)
1158 bool begin = pos == 0 || notfound ||
1159 (i > 0 && fontlist[i-1].pos == pos - 1);
1160 // Is position pos is a beginning of a font block?
1161 bool end = !notfound && fontlist[i].pos == pos;
1162 // Is position pos is the end of a font block?
1163 if (begin && end) { // A single char block
1164 if (i+1 < fontlist.size() &&
1165 fontlist[i+1].font == font) {
1166 // Merge the singleton block with the next block
1167 fontlist.erase(fontlist.begin() + i);
1168 if (i > 0 && fontlist[i-1].font == font)
1169 fontlist.erase(fontlist.begin() + i-1);
1170 } else if (i > 0 && fontlist[i-1].font == font) {
1171 // Merge the singleton block with the previous block
1172 fontlist[i-1].pos = pos;
1173 fontlist.erase(fontlist.begin() + i);
1175 fontlist[i].font = font;
1177 if (i > 0 && fontlist[i-1].font == font)
1178 fontlist[i-1].pos = pos;
1180 fontlist.insert(fontlist.begin() + i,
1181 FontTable(pos, font));
1183 fontlist[i].pos = pos - 1;
1184 if (!(i+1 < fontlist.size() &&
1185 fontlist[i+1].font == font))
1186 fontlist.insert(fontlist.begin() + i+1,
1187 FontTable(pos, font));
1188 } else { // The general case. The block is splitted into 3 blocks
1189 fontlist.insert(fontlist.begin() + i,
1190 FontTable(pos - 1, fontlist[i].font));
1191 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1196 // This function is able to hide closed footnotes.
1197 LyXParagraph * LyXParagraph::Next()
1200 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1201 LyXParagraph * tmp = next;
1203 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1205 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1206 return tmp->Next(); /* there can be more than one
1207 footnote in a logical
1210 return next; // This should never happen!
1217 LyXParagraph * LyXParagraph::NextAfterFootnote()
1220 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1221 LyXParagraph * tmp = next;
1222 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1224 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1225 return tmp; /* there can be more than one footnote
1226 in a logical paragraph */
1228 return next; // This should never happen!
1235 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1238 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1239 LyXParagraph * tmp = next;
1240 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1242 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1243 return tmp; /* there can be more than one footnote
1244 in a logical paragraph */
1246 return next; // This should never happen!
1253 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1257 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1259 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1260 tmp = tmp->previous;
1261 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1262 return tmp; /* there can be more than one footnote
1263 in a logical paragraph */
1265 return previous; // This should never happen!
1272 LyXParagraph * LyXParagraph::LastPhysicalPar()
1275 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1278 LyXParagraph * tmp = this;
1280 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1281 tmp = tmp->NextAfterFootnote();
1289 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1292 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1295 LyXParagraph const * tmp = this;
1297 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1298 tmp = tmp->NextAfterFootnote();
1306 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1311 LyXParagraph * tmppar = this;
1315 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1316 tmppar = tmppar->previous;
1328 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1333 LyXParagraph const * tmppar = this;
1337 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1338 tmppar = tmppar->previous;
1350 // This function is able to hide closed footnotes.
1351 LyXParagraph * LyXParagraph::Previous()
1353 LyXParagraph * tmp = previous;
1359 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1360 tmp = tmp->previous;
1362 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1363 tmp = tmp->previous;
1364 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1365 return tmp->next->Previous();
1375 // This function is able to hide closed footnotes.
1376 LyXParagraph const * LyXParagraph::Previous() const
1378 LyXParagraph * tmp = previous;
1383 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1384 tmp = tmp->previous;
1386 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1387 tmp = tmp->previous;
1388 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1389 return tmp->next->Previous();
1399 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1400 LyXParagraph::size_type pos,
1403 size_type i, j, pos_end, pos_first;
1404 // create a new paragraph
1405 LyXParagraph * par = ParFromPos(pos);
1406 LyXParagraph * firstpar = FirstPhysicalPar();
1408 LyXParagraph * tmp = new LyXParagraph(par);
1411 tmp->footnoteflag = footnoteflag;
1412 tmp->footnotekind = footnotekind;
1414 // this is an idea for a more userfriendly layout handling, I will
1415 // see what the users say
1417 // layout stays the same with latex-environments
1419 tmp->SetOnlyLayout(bparams, firstpar->layout);
1420 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1423 if (Last() > pos || !Last() || flag == 2) {
1424 tmp->SetOnlyLayout(bparams, firstpar->layout);
1425 tmp->align = firstpar->align;
1426 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1428 tmp->line_bottom = firstpar->line_bottom;
1429 firstpar->line_bottom = false;
1430 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1431 firstpar->pagebreak_bottom = false;
1432 tmp->added_space_bottom = firstpar->added_space_bottom;
1433 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1435 tmp->depth = firstpar->depth;
1436 tmp->noindent = firstpar->noindent;
1438 // copy everything behind the break-position
1439 // to the new paragraph
1441 while (ParFromPos(pos_first) != par)
1444 pos_end = pos_first + par->text.size() - 1;
1446 for (i = j = pos; i <= pos_end; ++i) {
1447 par->CutIntoMinibuffer(bparams, i - pos_first);
1448 if (tmp->InsertFromMinibuffer(j - pos))
1451 tmp->text.resize(tmp->text.size());
1452 for (i = pos_end; i >= pos; --i)
1453 par->Erase(i - pos_first);
1455 par->text.resize(par->text.size());
1458 // just an idea of me
1460 tmp->line_top = firstpar->line_top;
1461 tmp->pagebreak_top = firstpar->pagebreak_top;
1462 tmp->added_space_top = firstpar->added_space_top;
1463 tmp->bibkey = firstpar->bibkey;
1465 // layout stays the same with latex-environments
1467 firstpar->SetOnlyLayout(bparams, tmp->layout);
1468 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1469 firstpar->depth = tmp->depth;
1475 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1477 par = par->FirstPhysicalPar();
1479 footnoteflag = par->footnoteflag;
1480 footnotekind = par->footnotekind;
1482 layout = par->layout;
1483 align = par-> align;
1484 SetLabelWidthString(par->labelwidthstring);
1486 line_bottom = par->line_bottom;
1487 pagebreak_bottom = par->pagebreak_bottom;
1488 added_space_bottom = par->added_space_bottom;
1490 line_top = par->line_top;
1491 pagebreak_top = par->pagebreak_top;
1492 added_space_top = par->added_space_top;
1494 spacing = par->spacing;
1496 pextra_type = par->pextra_type;
1497 pextra_width = par->pextra_width;
1498 pextra_widthp = par->pextra_widthp;
1499 pextra_alignment = par->pextra_alignment;
1500 pextra_hfill = par->pextra_hfill;
1501 pextra_start_minipage = par->pextra_start_minipage;
1503 noindent = par->noindent;
1509 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1511 LyXParagraph * tmppar = this;
1514 && tmppar->previous->footnoteflag ==
1515 LyXParagraph::CLOSED_FOOTNOTE)
1516 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1517 tmppar = tmppar->previous;
1520 return this; // This should never happen!
1527 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1529 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1533 if (!IsDummy() && !table){
1535 && (IsNewline(0) || IsLineSeparator(0))){
1544 LyXParagraph * LyXParagraph::Clone() const
1546 // create a new paragraph
1547 LyXParagraph * result = new LyXParagraph;
1549 result->MakeSameLayout(this);
1551 // this is because of the dummy layout of the paragraphs that
1553 result->layout = layout;
1556 /* table stuff -- begin*/
1558 result->table = table->Clone();
1561 /* table stuff -- end*/
1563 result->inset_owner = inset_owner;
1566 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1569 // copy everything behind the break-position to the new paragraph
1571 result->text = text;
1572 result->fontlist = fontlist;
1573 result->insetlist = insetlist;
1574 for (InsetList::iterator it = result->insetlist.begin();
1575 it != result->insetlist.end(); ++it)
1576 (*it).inset = (*it).inset->Clone();
1581 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1583 par = par->FirstPhysicalPar();
1587 par->footnoteflag == footnoteflag &&
1588 par->footnotekind == footnotekind &&
1590 par->layout == layout &&
1592 par->align == align &&
1594 par->line_bottom == line_bottom &&
1595 par->pagebreak_bottom == pagebreak_bottom &&
1596 par->added_space_bottom == added_space_bottom &&
1598 par->line_top == line_top &&
1599 par->pagebreak_top == pagebreak_top &&
1600 par->added_space_top == added_space_top &&
1602 par->spacing == spacing &&
1604 par->pextra_type == pextra_type &&
1605 par->pextra_width == pextra_width &&
1606 par->pextra_widthp == pextra_widthp &&
1607 par->pextra_alignment == pextra_alignment &&
1608 par->pextra_hfill == pextra_hfill &&
1609 par->pextra_start_minipage == pextra_start_minipage &&
1611 par->table == table && // what means: NO TABLE AT ALL
1614 par->noindent == noindent &&
1615 par->depth == depth);
1619 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1620 LyXParagraph::size_type pos)
1622 // create a new paragraph
1623 LyXParagraph * par = ParFromPos(pos);
1625 LyXParagraph * tmp = new LyXParagraph(par);
1627 tmp->MakeSameLayout(par);
1629 // When can pos < Last()?
1630 // I guess pos == Last() is possible.
1632 // copy everything behind the break-position to the new
1634 size_type pos_first = 0;
1635 while (ParFromPos(pos_first) != par)
1637 size_type pos_end = pos_first + par->text.size() - 1;
1640 for (i = j = pos; i <= pos_end; ++i) {
1641 par->CutIntoMinibuffer(bparams, i - pos_first);
1642 if (tmp->InsertFromMinibuffer(j - pos))
1645 tmp->text.resize(tmp->text.size());
1646 for (size_type i = pos_end; i >= pos; --i)
1647 par->Erase(i - pos_first);
1649 par->text.resize(par->text.size());
1654 // Be carefull, this does not make any check at all.
1655 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1657 // copy the next paragraph to this one
1658 LyXParagraph * the_next = Next();
1660 LyXParagraph * firstpar = FirstPhysicalPar();
1662 // first the DTP-stuff
1663 firstpar->line_bottom = the_next->line_bottom;
1664 firstpar->added_space_bottom = the_next->added_space_bottom;
1665 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1667 size_type pos_end = the_next->text.size() - 1;
1668 size_type pos_insert = Last();
1670 // ok, now copy the paragraph
1672 for (i = j = 0; i <= pos_end; ++i) {
1673 the_next->CutIntoMinibuffer(bparams, i);
1674 if (InsertFromMinibuffer(pos_insert + j))
1678 // delete the next paragraph
1679 LyXParagraph * ppar = the_next->previous;
1680 LyXParagraph * npar = the_next->next;
1687 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1689 LyXParagraph * par = ParFromPos(pos);
1691 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1692 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1698 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1700 LyXParagraph * par = ParFromPos(pos);
1702 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1703 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1709 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1711 LyXParagraph const * par = this;
1712 int par_depth = GetDepth();
1714 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1716 textclasslist.Style(bparams.textclass,
1717 layout).endlabeltype;
1718 if (endlabeltype != END_LABEL_NO_LABEL) {
1719 LyXParagraph const * last = this;
1720 if( footnoteflag == NO_FOOTNOTE)
1721 last = LastPhysicalPar();
1722 else if (next->footnoteflag == NO_FOOTNOTE)
1723 return endlabeltype;
1725 if (!last || !last->next)
1726 return endlabeltype;
1728 int next_depth = last->next->GetDepth();
1729 if (par_depth > next_depth ||
1730 (par_depth == next_depth && layout != last->next->GetLayout() ))
1731 return endlabeltype;
1736 par = par->DepthHook(par_depth - 1);
1738 par_depth = par->GetDepth();
1740 return END_LABEL_NO_LABEL;
1744 LyXTextClass::size_type LyXParagraph::GetLayout() const
1746 return FirstPhysicalPar()->layout;
1750 char LyXParagraph::GetDepth() const
1752 return FirstPhysicalPar()->depth;
1756 char LyXParagraph::GetAlign() const
1758 return FirstPhysicalPar()->align;
1762 string LyXParagraph::GetLabelstring() const
1764 return FirstPhysicalPar()->labelstring;
1768 int LyXParagraph::GetFirstCounter(int i) const
1770 return FirstPhysicalPar()->counter_[i];
1774 // the next two functions are for the manual labels
1775 string LyXParagraph::GetLabelWidthString() const
1777 if (!FirstPhysicalPar()->labelwidthstring.empty())
1778 return FirstPhysicalPar()->labelwidthstring;
1780 return _("Senseless with this layout!");
1784 void LyXParagraph::SetLabelWidthString(string const & s)
1786 LyXParagraph * par = FirstPhysicalPar();
1788 par->labelwidthstring = s;
1792 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1793 LyXTextClass::size_type new_layout)
1795 LyXParagraph * par = FirstPhysicalPar();
1796 LyXParagraph * ppar = 0;
1797 LyXParagraph * npar = 0;
1799 par->layout = new_layout;
1801 /* table stuff -- begin*/
1804 /* table stuff -- end*/
1806 if (par->pextra_type == PEXTRA_NONE) {
1807 if (par->Previous()) {
1808 ppar = par->Previous()->FirstPhysicalPar();
1811 && (ppar->depth > par->depth))
1812 ppar = ppar->Previous()->FirstPhysicalPar();
1815 npar = par->Next()->NextAfterFootnote();
1818 && (npar->depth > par->depth))
1819 npar = npar->Next()->NextAfterFootnote();
1821 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1823 p1 = ppar->pextra_width,
1824 p2 = ppar->pextra_widthp;
1825 ppar->SetPExtraType(bparams, ppar->pextra_type,
1826 p1.c_str(), p2.c_str());
1828 if ((par->pextra_type == PEXTRA_NONE) &&
1829 npar && (npar->pextra_type != PEXTRA_NONE)) {
1831 p1 = npar->pextra_width,
1832 p2 = npar->pextra_widthp;
1833 npar->SetPExtraType(bparams, npar->pextra_type,
1834 p1.c_str(), p2.c_str());
1840 void LyXParagraph::SetLayout(BufferParams const & bparams,
1841 LyXTextClass::size_type new_layout)
1844 * par = FirstPhysicalPar(),
1848 par->layout = new_layout;
1849 par->labelwidthstring.erase();
1850 par->align = LYX_ALIGN_LAYOUT;
1851 par->added_space_top = VSpace(VSpace::NONE);
1852 par->added_space_bottom = VSpace(VSpace::NONE);
1853 par->spacing.set(Spacing::Default);
1856 /* table stuff -- begin*/
1859 /* table stuff -- end*/
1861 if (par->pextra_type == PEXTRA_NONE) {
1862 if (par->Previous()) {
1863 ppar = par->Previous()->FirstPhysicalPar();
1866 && (ppar->depth > par->depth))
1867 ppar = ppar->Previous()->FirstPhysicalPar();
1870 npar = par->Next()->NextAfterFootnote();
1873 && (npar->depth > par->depth))
1874 npar = npar->Next()->NextAfterFootnote();
1876 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1878 p1 = ppar->pextra_width,
1879 p2 = ppar->pextra_widthp;
1880 ppar->SetPExtraType(bparams, ppar->pextra_type,
1881 p1.c_str(), p2.c_str());
1883 if ((par->pextra_type == PEXTRA_NONE) &&
1884 npar && (npar->pextra_type != PEXTRA_NONE)) {
1886 p1 = npar->pextra_width,
1887 p2 = npar->pextra_widthp;
1888 npar->SetPExtraType(bparams, npar->pextra_type,
1889 p1.c_str(), p2.c_str());
1895 // if the layout of a paragraph contains a manual label, the beginning of the
1896 // main body is the beginning of the second word. This is what the par-
1897 // function returns. If the layout does not contain a label, the main
1898 // body always starts with position 0. This differentiation is necessary,
1899 // because there cannot be a newline or a blank <= the beginning of the
1900 // main body in TeX.
1902 int LyXParagraph::BeginningOfMainBody() const
1904 if (FirstPhysicalPar() != this)
1907 // Unroll the first two cycles of the loop
1908 // and remember the previous character to
1909 // remove unnecessary GetChar() calls
1912 && GetChar(i) != LyXParagraph::META_NEWLINE
1915 char previous_char = 0, temp = 0;
1917 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1918 // Yes, this ^ is supposed to be "= " not "=="
1921 && previous_char != ' '
1922 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1924 previous_char = temp;
1929 if (i == 0 && i == size() &&
1930 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1931 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1932 ++i; /* the cursor should not jump
1933 * to the main body if there
1939 LyXParagraph * LyXParagraph::DepthHook(int deth)
1941 LyXParagraph * newpar = this;
1946 newpar = newpar->FirstPhysicalPar()->Previous();
1947 } while (newpar && newpar->GetDepth() > deth
1948 && newpar->footnoteflag == footnoteflag);
1951 if (Previous() || GetDepth())
1952 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1956 return newpar->FirstPhysicalPar();
1960 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1962 LyXParagraph const * newpar = this;
1967 newpar = newpar->FirstPhysicalPar()->Previous();
1968 } while (newpar && newpar->GetDepth() > deth
1969 && newpar->footnoteflag == footnoteflag);
1972 if (Previous() || GetDepth())
1973 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1977 return newpar->FirstPhysicalPar();
1981 int LyXParagraph::AutoDeleteInsets()
1984 InsetList::size_type index = 0;
1985 while (index < insetlist.size()) {
1986 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1987 Erase(insetlist[index].pos);
1988 // Erase() calls to insetlist.erase(&insetlist[index])
1989 // so index shouldn't be increased.
1998 LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2000 InsetList::iterator it = lower_bound(insetlist.begin(),
2003 return inset_iterator(it);
2007 // returns -1 if inset not found
2008 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2011 // We could use lower_bound here too, we just need to add
2012 // the approp. operator() to matchIT (and change the name
2013 // of that struct). Code would then be:
2014 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2016 // inset, matchIT());
2017 // if ((*cit).inset == inset) {
2018 // return (*cit).pos;
2020 for (InsetList::const_iterator cit = insetlist.begin();
2021 cit != insetlist.end(); ++cit) {
2022 if ((*cit).inset == inset) {
2026 // Think about footnotes.
2027 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2028 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2030 NextAfterFootnote()->GetPositionOfInset(inset);
2032 return text.size() + 1 + further;
2038 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2039 BufferParams const & bparams,
2040 ostream & os, TexRow & texrow,
2043 TexRow & foot_texrow,
2046 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2047 LyXLayout const & style =
2048 textclasslist.Style(bparams.textclass,
2051 bool further_blank_line = false;
2053 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2055 if (start_of_appendix) {
2056 os << "\\appendix\n";
2060 if (!spacing.isDefault()
2061 && (!Previous() || !Previous()->HasSameLayout(this))) {
2062 os << spacing.writeEnvirBegin() << "\n";
2066 if (tex_code_break_column && style.isCommand()){
2071 if (pagebreak_top) {
2073 further_blank_line = true;
2075 if (added_space_top.kind() != VSpace::NONE) {
2076 os << added_space_top.asLatexCommand(bparams);
2077 further_blank_line = true;
2081 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2082 << "\\vspace{-1\\parskip}";
2083 further_blank_line = true;
2086 if (further_blank_line){
2091 Language const * language = getParLanguage(bparams);
2092 Language const * doc_language = bparams.language_info;
2093 if (language != doc_language &&
2094 (!previous || previous->getParLanguage(bparams) != language)) {
2095 os << subst(lyxrc.language_command_begin, "$$lang",
2101 switch (style.latextype) {
2104 << style.latexname()
2105 << style.latexparam();
2107 case LATEX_ITEM_ENVIRONMENT:
2109 bibkey->Latex(buf, os, false, false);
2113 case LATEX_LIST_ENVIRONMENT:
2120 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2123 // Spit out footnotes
2124 LyXParagraph * par = next;
2125 if (lyxrc.rtl_support) {
2126 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2127 && next->footnoteflag != footnoteflag) {
2128 LyXParagraph * p = 0;
2129 bool is_rtl = (size() > 0)
2130 ? GetFontSettings(bparams,
2131 size()-1).isRightToLeft()
2132 : language->RightToLeft();
2133 if ( (p = NextAfterFootnote()) != 0 &&
2135 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2136 is_rtl = getParLanguage(bparams)->RightToLeft();
2137 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2138 && par->footnoteflag != footnoteflag) {
2139 par = par->TeXFootnote(buf, bparams,
2141 foot_texrow, foot_count,
2143 par->SimpleTeXOnePar(buf, bparams,
2144 os, texrow, moving_arg);
2145 is_rtl = (par->size() > 0)
2146 ? par->GetFontSettings(bparams,
2147 par->size()-1).isRightToLeft()
2148 : language->RightToLeft();
2150 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2151 (p = par->NextAfterFootnote()) != 0 &&
2153 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2154 is_rtl = language->RightToLeft();
2159 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2160 && par->footnoteflag != footnoteflag) {
2161 par = par->TeXFootnote(buf, bparams,
2163 foot, foot_texrow, foot_count,
2165 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2171 // Make sure that \\par is done with the font of the last
2172 // character if this has another size as the default.
2173 // This is necessary because LaTeX (and LyX on the screen)
2174 // calculates the space between the baselines according
2175 // to this font. (Matthias)
2176 LyXFont font = getFont(bparams, Last() - 1);
2178 if (style.resfont.size() != font.size()) {
2184 } else if (textclasslist.Style(bparams.textclass,
2185 GetLayout()).isCommand()) {
2186 if (style.resfont.size() != font.size()) {
2192 } else if (style.resfont.size() != font.size()){
2193 os << "{\\" << font.latexSize() << " \\par}";
2196 if (language != doc_language &&
2198 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2199 || par->getParLanguage(bparams) != language)) {
2201 << subst(lyxrc.language_command_end, "$$lang",
2202 doc_language->lang());
2205 switch (style.latextype) {
2206 case LATEX_ITEM_ENVIRONMENT:
2207 case LATEX_LIST_ENVIRONMENT:
2208 if (par && (depth < par->depth)) {
2213 case LATEX_ENVIRONMENT:
2214 // if its the last paragraph of the current environment
2215 // skip it otherwise fall through
2217 && (par->layout != layout
2218 || par->depth != depth
2219 || par->pextra_type != pextra_type))
2222 // we don't need it for the last paragraph!!!
2223 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2224 && footnotekind != LyXParagraph::FOOTNOTE
2225 && footnotekind != LyXParagraph::MARGIN
2229 // don't insert this if we would be adding it
2230 // before or after a table in a float. This
2231 // little trick is needed in order to allow
2232 // use of tables in \subfigures or \subtables.
2238 further_blank_line = false;
2240 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2241 further_blank_line = true;
2244 if (added_space_bottom.kind() != VSpace::NONE) {
2245 os << added_space_bottom.asLatexCommand(bparams);
2246 further_blank_line = true;
2249 if (pagebreak_bottom) {
2251 further_blank_line = true;
2254 if (further_blank_line){
2259 if (!spacing.isDefault()
2260 && (!par || !par->HasSameLayout(this))) {
2261 os << spacing.writeEnvirEnd() << "\n";
2265 // we don't need it for the last paragraph!!!
2266 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2267 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2272 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2277 // This one spits out the text of the paragraph
2278 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2279 BufferParams const & bparams,
2280 ostream & os, TexRow & texrow,
2283 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2287 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2290 bool return_value = false;
2292 LyXLayout const & style =
2293 textclasslist.Style(bparams.textclass,
2295 LyXFont basefont, last_font;
2297 // Maybe we have to create a optional argument.
2298 size_type main_body;
2299 if (style.labeltype != LABEL_MANUAL)
2302 main_body = BeginningOfMainBody();
2304 if (main_body > 0) {
2306 basefont = getFont(bparams, -2); // Get label font
2308 basefont = getFont(bparams, -1); // Get layout font
2316 if (style.isCommand()) {
2319 } else if (align != LYX_ALIGN_LAYOUT) {
2322 return_value = true;
2326 moving_arg |= style.needprotect;
2328 // Which font is currently active?
2329 LyXFont running_font(basefont);
2330 // Do we have an open font change?
2331 bool open_font = false;
2333 texrow.start(this, 0);
2335 for (size_type i = 0; i < size(); ++i) {
2337 // First char in paragraph or after label?
2338 if (i == main_body && !IsDummy()) {
2339 if (main_body > 0) {
2341 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2344 basefont = getFont(bparams, -1); // Now use the layout font
2345 running_font = basefont;
2349 if (style.isCommand()) {
2352 } else if (align != LYX_ALIGN_LAYOUT) {
2355 return_value = true;
2359 os << "\\noindent ";
2363 case LYX_ALIGN_NONE:
2364 case LYX_ALIGN_BLOCK:
2365 case LYX_ALIGN_LAYOUT:
2366 case LYX_ALIGN_SPECIAL:
2368 case LYX_ALIGN_LEFT:
2369 if (getParLanguage(bparams)->lang() != "hebrew") {
2370 os << "\\raggedright ";
2373 os << "\\raggedleft ";
2377 case LYX_ALIGN_RIGHT:
2378 if (getParLanguage(bparams)->lang() != "hebrew") {
2379 os << "\\raggedleft ";
2382 os << "\\raggedright ";
2386 case LYX_ALIGN_CENTER:
2387 os << "\\centering ";
2395 // Fully instantiated font
2396 LyXFont font = getFont(bparams, i);
2397 LyXParagraph * p = 0;
2398 if (i == 0 && previous &&
2399 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2400 (p = PreviousBeforeFootnote()) != 0)
2401 last_font = p->getFont(bparams, p->size()-1);
2403 last_font = running_font;
2405 // Spaces at end of font change are simulated to be
2406 // outside font change, i.e. we write "\textXX{text} "
2407 // rather than "\textXX{text }". (Asger)
2408 if (open_font && c == ' ' && i <= size() - 2
2409 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2410 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2411 font = getFont(bparams, i + 1);
2413 // We end font definition before blanks
2414 if (!font.equalExceptLatex(running_font) && open_font) {
2415 column += running_font.latexWriteEndChanges(os,
2417 (i == main_body-1) ? basefont : font);
2418 running_font = basefont;
2422 // Blanks are printed before start of fontswitch
2424 // Do not print the separation of the optional argument
2425 if (i != main_body - 1) {
2426 SimpleTeXBlanks(os, texrow, i,
2427 column, font, style);
2431 // Do we need to change font?
2432 if (!font.equalExceptLatex(running_font)
2433 && i != main_body-1) {
2434 column += font.latexWriteStartChanges(os, basefont,
2436 running_font = font;
2440 if (c == LyXParagraph::META_NEWLINE) {
2441 // newlines are handled differently here than
2442 // the default in SimpleTeXSpecialChars().
2443 if (!style.newline_allowed
2444 || font.latex() == LyXFont::ON) {
2448 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2451 basefont = getFont(bparams, -1);
2452 running_font = basefont;
2453 if (font.family() ==
2454 LyXFont::TYPEWRITER_FAMILY) {
2462 texrow.start(this, i + 1);
2465 SimpleTeXSpecialChars(buf, bparams,
2466 os, texrow, moving_arg,
2467 font, running_font, basefont,
2468 open_font, style, i, column, c);
2472 // If we have an open font definition, we have to close it
2474 LyXParagraph * p = 0;
2475 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2476 && (p = NextAfterFootnote()) != 0)
2477 running_font.latexWriteEndChanges(os, basefont,
2478 p->getFont(bparams, 0));
2480 running_font.latexWriteEndChanges(os, basefont, basefont);
2483 // Needed if there is an optional argument but no contents.
2484 if (main_body > 0 && main_body == size()) {
2486 return_value = false;
2489 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2490 return return_value;
2494 // This one spits out the text of a table paragraph
2495 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2496 BufferParams const & bparams,
2497 ostream & os, TexRow & texrow)
2499 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2501 bool return_value = false;
2503 LyXLayout const & style =
2504 textclasslist.Style(bparams.textclass, GetLayout());
2507 if (!IsDummy()) { // it is dummy if it is in a float!!!
2508 if (style.isCommand()) {
2511 } else if (align != LYX_ALIGN_LAYOUT) {
2514 return_value = true;
2517 os << "\\noindent ";
2521 case LYX_ALIGN_NONE:
2522 case LYX_ALIGN_BLOCK:
2523 case LYX_ALIGN_LAYOUT:
2524 case LYX_ALIGN_SPECIAL: break;
2525 case LYX_ALIGN_LEFT:
2526 os << "\\raggedright ";
2529 case LYX_ALIGN_RIGHT:
2530 os << "\\raggedleft ";
2533 case LYX_ALIGN_CENTER:
2534 os << "\\centering ";
2540 LyXFont basefont = getFont(bparams, -1); // Get layout font
2541 // Which font is currently active?
2542 LyXFont running_font = basefont;
2544 // Do we have an open font change?
2545 bool open_font = false;
2546 int current_cell_number = -1;
2547 int tmp = table->TexEndOfCell(os, current_cell_number);
2548 for (; tmp > 0 ; --tmp)
2551 texrow.start(this, 0);
2553 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2554 bool first_in_cell = true;
2556 for (size_type i = 0; i < size(); ++i) {
2557 char c = GetChar(i);
2558 if (table->IsContRow(current_cell_number + 1)) {
2559 if (c == LyXParagraph::META_NEWLINE)
2560 ++current_cell_number;
2565 if (first_in_cell && is_rtl) {
2568 first_in_cell = false;
2571 // Fully instantiated font
2572 LyXFont font = getFont(bparams, i);
2573 last_font = running_font;
2575 // Spaces at end of font change are simulated to be
2576 // outside font change.
2577 // i.e. we write "\textXX{text} " rather than
2578 // "\textXX{text }". (Asger)
2579 if (open_font && c == ' ' && i <= size() - 2
2580 && getFont(bparams, i + 1) != running_font
2581 && getFont(bparams, i + 1) != font) {
2582 font = getFont(bparams, i + 1);
2585 // We end font definition before blanks
2586 if (font != running_font && open_font) {
2587 column += running_font.latexWriteEndChanges(os,
2590 running_font = basefont;
2593 // Blanks are printed before start of fontswitch
2595 SimpleTeXBlanks(os, texrow, i, column, font, style);
2597 // Do we need to change font?
2598 if (font != running_font) {
2599 column += font.latexWriteStartChanges(os, basefont,
2601 running_font = font;
2604 // Do we need to turn on LaTeX mode?
2605 if (font.latex() != running_font.latex()) {
2606 if (font.latex() == LyXFont::ON
2607 && style.needprotect) {
2612 if (c == LyXParagraph::META_NEWLINE) {
2613 // special case for inside a table
2614 // different from default case in
2615 // SimpleTeXSpecialChars()
2617 column += running_font
2618 .latexWriteEndChanges(os, basefont,
2622 basefont = getFont(bparams, -1);
2623 running_font = basefont;
2624 ++current_cell_number;
2625 if (table->CellHasContRow(current_cell_number) >= 0) {
2626 TeXContTableRows(buf, bparams, os, i + 1,
2627 current_cell_number,
2630 if (is_rtl && !first_in_cell) {
2632 first_in_cell = true;
2635 // if this cell follow only ContRows till end don't
2636 // put the EndOfCell because it is put after the
2638 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2639 --current_cell_number;
2642 int tmp = table->TexEndOfCell(os,
2643 current_cell_number);
2646 } else if (tmp < 0) {
2652 texrow.start(this, i + 1);
2654 SimpleTeXSpecialChars(buf, bparams,
2656 font, running_font, basefont,
2657 open_font, style, i, column, c);
2661 // If we have an open font definition, we have to close it
2663 running_font.latexWriteEndChanges(os, basefont, basefont);
2665 ++current_cell_number;
2666 if (is_rtl && !first_in_cell)
2668 tmp = table->TexEndOfCell(os, current_cell_number);
2669 for (; tmp > 0; --tmp)
2671 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2672 return return_value;
2676 // This one spits out the text off ContRows in tables
2677 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2678 BufferParams const & bparams,
2680 LyXParagraph::size_type i,
2681 int current_cell_number,
2682 int & column, TexRow & texrow)
2684 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2688 bool return_value = false;
2689 LyXLayout const & style =
2690 textclasslist.Style(bparams.textclass,
2692 LyXFont basefont = getFont(bparams, -1); // Get layout font
2694 // Which font is currently active?
2695 LyXFont running_font = basefont;
2696 // Do we have an open font change?
2697 bool open_font = false;
2699 size_type lastpos = i;
2700 int cell = table->CellHasContRow(current_cell_number);
2701 ++current_cell_number;
2704 // first find the right position
2706 for (; (i < size()) && (current_cell_number<cell); ++i) {
2708 if (c == LyXParagraph::META_NEWLINE)
2709 ++current_cell_number;
2713 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2717 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2722 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2726 // Fully instantiated font
2727 LyXFont font = getFont(bparams, i);
2728 last_font = running_font;
2730 // Spaces at end of font change are simulated to
2731 // be outside font change. i.e. we write
2732 // "\textXX{text} " rather than "\textXX{text }".
2734 if (open_font && c == ' ' && i <= size() - 2
2735 && getFont(bparams, i + 1) != running_font
2736 && getFont(bparams, i + 1) != font) {
2737 font = getFont(bparams, i + 1);
2740 // We end font definition before blanks
2741 if (font != running_font && open_font) {
2742 column += running_font.latexWriteEndChanges(os, basefont, font);
2743 running_font = basefont;
2746 // Blanks are printed before start of fontswitch
2748 SimpleTeXBlanks(os, texrow, i,
2749 column, font, style);
2751 // Do we need to change font?
2752 if (font != running_font) {
2754 font.latexWriteStartChanges(os,
2757 running_font = font;
2760 // Do we need to turn on LaTeX mode?
2761 if (font.latex() != running_font.latex()) {
2762 if (font.latex() == LyXFont::ON
2763 && style.needprotect) {
2768 SimpleTeXSpecialChars(buf, bparams,
2769 os, texrow, false, font,
2770 running_font, basefont,
2771 open_font, style, i, column, c);
2773 // If we have an open font definition, we have to close it
2775 running_font.latexWriteEndChanges(os, basefont,
2779 basefont = getFont(bparams, -1);
2780 running_font = basefont;
2781 cell = table->CellHasContRow(current_cell_number);
2783 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2784 return return_value;
2788 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2790 bool retval = false;
2792 case LyXParagraph::META_HFILL:
2793 sgml_string.erase();
2795 case LyXParagraph::META_NEWLINE:
2799 sgml_string = "&";
2802 sgml_string = "<";
2805 sgml_string = ">";
2808 sgml_string = "$";
2811 sgml_string = "#";
2814 sgml_string = "%";
2817 sgml_string = "[";
2820 sgml_string = "]";
2823 sgml_string = "{";
2826 sgml_string = "}";
2829 sgml_string = "˜";
2832 sgml_string = """;
2835 sgml_string = "\";
2841 case '\0': // Ignore :-)
2842 sgml_string.erase();
2852 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
2853 ostream & os, string & extra,
2854 int & desc_on, int depth)
2856 BufferParams const & bparams = buffer->params;
2858 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2860 LyXFont font1, font2;
2863 size_type main_body;
2864 bool emph_flag = false;
2866 LyXLayout const & style =
2867 textclasslist.Style(bparams.textclass,
2870 if (style.labeltype != LABEL_MANUAL)
2873 main_body = BeginningOfMainBody();
2875 // Gets paragraph main font.
2877 font1 = style.labelfont;
2881 int char_line_count = depth;
2882 os << newlineAndDepth(depth);
2883 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2884 os << "<INFORMALTABLE>"
2885 << newlineAndDepth(++depth);
2887 int current_cell_number = -1;
2888 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2890 // Parsing main loop.
2891 for (size_type i = 0; i < size(); ++i) {
2893 if (table->IsContRow(current_cell_number+1)) {
2894 if (c == LyXParagraph::META_NEWLINE)
2895 ++current_cell_number;
2900 // Fully instantiated font
2901 font2 = getFont(bparams, i);
2903 // Handle <emphasis> tag.
2904 if (font1.emph() != font2.emph() && i) {
2905 if (font2.emph() == LyXFont::ON) {
2908 } else if (emph_flag) {
2909 os << "</emphasis>";
2913 if (c == LyXParagraph::META_NEWLINE) {
2914 // We have only to control for emphasis open here!
2916 os << "</emphasis>";
2919 font1 = font2 = getFont(bparams, -1);
2920 ++current_cell_number;
2921 if (table->CellHasContRow(current_cell_number) >= 0) {
2922 DocBookContTableRows(buffer,
2923 os, extra, desc_on, i + 1,
2924 current_cell_number,
2927 // if this cell follow only ContRows till end don't
2928 // put the EndOfCell because it is put after the
2930 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2931 --current_cell_number;
2934 tmp = table->DocBookEndOfCell(os,
2935 current_cell_number,
2940 } else if (c == LyXParagraph::META_INSET) {
2941 inset = GetInset(i);
2943 std::ostringstream ost;
2944 inset->DocBook(buffer, ost);
2945 string tmp_out = ost.str().c_str();
2948 inset->DocBook(buffer, ost);
2950 char * ctmp = ost.str();
2951 string tmp_out(ctmp);
2955 // This code needs some explanation:
2956 // Two insets are treated specially
2957 // label if it is the first element in a
2958 // command paragraph
2960 // graphics inside tables or figure floats
2962 // title (the equivalente in latex for this
2964 // and title should come first
2967 if(desc_on != 3 || i != 0) {
2968 if(tmp_out[0] == '@') {
2970 extra += frontStrip(tmp_out,
2973 os << frontStrip(tmp_out,
2978 } else if (font2.latex() == LyXFont::ON) {
2979 // "TeX"-Mode on == > SGML-Mode on.
2985 if (linuxDocConvertChar(c, sgml_string)
2986 && !style.free_spacing) {
2987 // in freespacing mode, spaces are
2988 // non-breaking characters
2993 << "</term><listitem><para>";
3005 // Needed if there is an optional argument but no contents.
3006 if (main_body > 0 && main_body == size()) {
3011 os << "</emphasis>";
3014 ++current_cell_number;
3015 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3016 // Resets description flag correctly.
3019 // <term> not closed...
3023 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3024 os << "</INFORMALTABLE>";
3026 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3031 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3032 ostream & os, string & extra,
3034 LyXParagraph::size_type i,
3035 int current_cell_number, int &column)
3040 BufferParams const & bparams = buffer->params;
3042 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3047 //string emph = "emphasis";
3048 bool emph_flag = false;
3049 int char_line_count = 0;
3051 LyXLayout const & style =
3052 textclasslist.Style(bparams.textclass,
3055 size_type main_body;
3056 if (style.labeltype != LABEL_MANUAL)
3059 main_body = BeginningOfMainBody();
3061 // Gets paragraph main font.
3064 font1 = style.labelfont;
3068 size_type lastpos = i;
3069 int cell = table->CellHasContRow(current_cell_number);
3070 ++current_cell_number;
3072 // first find the right position
3074 for (; i < size() && current_cell_number < cell; ++i) {
3076 if (c == LyXParagraph::META_NEWLINE)
3077 ++current_cell_number;
3081 // I don't know how to handle this so I comment it
3082 // for the moment (Jug)
3083 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3084 // file += " \\\\\n";
3087 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3092 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3096 // Fully instantiated font
3097 font2 = getFont(bparams, i);
3099 // Handle <emphasis> tag.
3100 if (font1.emph() != font2.emph() && i) {
3101 if (font2.emph() == LyXFont::ON) {
3104 } else if (emph_flag) {
3105 os << "</emphasis>";
3109 if (c == LyXParagraph::META_INSET) {
3110 inset = GetInset(i);
3112 std::ostringstream ost;
3113 inset->DocBook(buffer, ost);
3114 string tmp_out = ost.str().c_str();
3117 inset->DocBook(buffer, ost);
3119 char * ctmp = ost.str();
3120 string tmp_out(ctmp);
3124 // This code needs some explanation:
3125 // Two insets are treated specially
3126 // label if it is the first element in a
3127 // command paragraph
3129 // graphics inside tables or figure floats
3130 // can't go on title (the equivalente in
3131 // latex for this case is caption and title
3132 // should come first
3135 if(desc_on != 3 || i != 0) {
3136 if(tmp_out[0] == '@') {
3138 extra += frontStrip(tmp_out, '@');
3140 os << frontStrip(tmp_out, '@');
3144 } else if (font2.latex() == LyXFont::ON) {
3145 // "TeX"-Mode on == > SGML-Mode on.
3151 if (linuxDocConvertChar(c, sgml_string)
3152 && !style.free_spacing) {
3153 // in freespacing mode, spaces are
3154 // non-breaking characters
3159 << "</term><listitem><para>";
3169 // we have only to control for emphasis open here!
3171 os << "</emphasis>";
3174 font1 = font2 = getFont(bparams, -1);
3175 cell = table->CellHasContRow(current_cell_number);
3177 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3181 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3182 LyXParagraph::size_type const i,
3183 int & column, LyXFont const & font,
3184 LyXLayout const & style)
3186 if (column > tex_code_break_column
3188 && GetChar(i - 1) != ' '
3190 // In LaTeX mode, we don't want to
3191 // break lines since some commands
3193 && ! (font.latex() == LyXFont::ON)
3194 // same in FreeSpacing mode
3195 && !style.free_spacing
3196 // In typewriter mode, we want to avoid
3197 // ! . ? : at the end of a line
3198 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3199 && (GetChar(i-1) == '.'
3200 || GetChar(i-1) == '?'
3201 || GetChar(i-1) == ':'
3202 || GetChar(i-1) == '!'))) {
3203 if (tex_code_break_column == 0) {
3204 // in batchmode we need LaTeX to still
3205 // see it as a space not as an extra '\n'
3211 texrow.start(this, i + 1);
3213 } else if (font.latex() == LyXFont::OFF) {
3214 if (style.free_spacing) {
3223 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3224 BufferParams const & bparams,
3225 ostream & os, TexRow & texrow,
3228 LyXFont & running_font,
3231 LyXLayout const & style,
3232 LyXParagraph::size_type & i,
3233 int & column, char const c)
3235 // Two major modes: LaTeX or plain
3236 // Handle here those cases common to both modes
3237 // and then split to handle the two modes separately.
3239 case LyXParagraph::META_INSET: {
3240 Inset * inset = GetInset(i);
3243 int len = os.tellp();
3244 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3245 || inset->LyxCode() == Inset::MATH_CODE
3246 || inset->LyxCode() == Inset::URL_CODE)
3247 && running_font.isRightToLeft()) {
3252 int tmp = inset->Latex(buf, os, moving_arg,
3253 style.free_spacing);
3261 column += os.tellp() - len;
3270 case LyXParagraph::META_NEWLINE:
3272 column += running_font.latexWriteEndChanges(os,
3277 basefont = getFont(bparams, -1);
3278 running_font = basefont;
3281 case LyXParagraph::META_HFILL:
3287 // And now for the special cases within each mode
3288 // Are we in LaTeX mode?
3289 if (font.latex() == LyXFont::ON) {
3290 // at present we only have one option
3291 // but I'll leave it as a switch statement
3292 // so its simpler to extend. (ARRae)
3295 // make sure that we will not print
3296 // error generating chars to the tex
3297 // file. This test would not be needed
3298 // if it were done in the buffer
3306 // Plain mode (i.e. not LaTeX)
3309 os << "\\textbackslash{}";
3313 case '°': case '±': case '²': case '³':
3314 case '×': case '÷': case '¹': case 'ª':
3315 case 'º': case '¬': case 'µ':
3316 if (bparams.inputenc == "latin1") {
3317 os << "\\ensuremath{"
3326 case '|': case '<': case '>':
3327 // In T1 encoding, these characters exist
3328 if (lyxrc.fontenc == "T1") {
3330 //... but we should avoid ligatures
3331 if ((c == '>' || c == '<')
3333 && GetChar(i + 1) == c){
3334 os << "\\textcompwordmark{}";
3339 // Typewriter font also has them
3340 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3344 // Otherwise, we use what LaTeX
3348 os << "\\textless{}";
3352 os << "\\textgreater{}";
3356 os << "\\textbar{}";
3362 case '-': // "--" in Typewriter mode -> "-{}-"
3364 && GetChar(i + 1) == '-'
3365 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3374 os << "\\char`\\\"{}";
3379 if (bparams.inputenc == "default") {
3388 case '%': case '#': case '{':
3395 os << "\\textasciitilde{}";
3400 os << "\\textasciicircum{}";
3404 case '*': case '[': case ']':
3405 // avoid being mistaken for optional arguments
3406 os << '{' << c << '}';
3411 // Blanks are printed before font switching.
3412 // Sure? I am not! (try nice-latex)
3413 // I am sure it's correct. LyX might be smarter
3414 // in the future, but for now, nothing wrong is
3419 /* idea for labels --- begin*/
3423 && font.family() != LyXFont::TYPEWRITER_FAMILY
3424 && GetChar(i + 1) == 'y'
3425 && GetChar(i + 2) == 'X') {
3433 && font.family() != LyXFont::TYPEWRITER_FAMILY
3434 && GetChar(i + 1) == 'e'
3435 && GetChar(i + 2) == 'X') {
3440 // Check for "LaTeX2e"
3443 && font.family() != LyXFont::TYPEWRITER_FAMILY
3444 && GetChar(i + 1) == 'a'
3445 && GetChar(i + 2) == 'T'
3446 && GetChar(i + 3) == 'e'
3447 && GetChar(i + 4) == 'X'
3448 && GetChar(i + 5) == '2'
3449 && GetChar(i + 6) == 'e') {
3454 // Check for "LaTeX"
3457 && font.family() != LyXFont::TYPEWRITER_FAMILY
3458 && GetChar(i + 1) == 'a'
3459 && GetChar(i + 2) == 'T'
3460 && GetChar(i + 3) == 'e'
3461 && GetChar(i + 4) == 'X') {
3465 /* idea for labels --- end*/
3466 } else if (c != '\0') {
3476 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3477 BufferParams const & bparams,
3478 ostream & os, TexRow & texrow,
3480 TexRow & foot_texrow,
3483 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3484 LyXParagraph * par = this;
3487 (par->depth == depth) &&
3488 (par->footnoteflag == footnoteflag)) {
3490 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3491 if (textclasslist.Style(bparams.textclass,
3492 par->layout).isEnvironment()
3493 || par->pextra_type != PEXTRA_NONE) {
3494 par = par->TeXEnvironment(buf, bparams,
3499 par = par->TeXOnePar(buf, bparams,
3505 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3511 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3512 BufferParams const & bparams,
3513 ostream & os, TexRow & texrow,
3515 TexRow & foot_texrow,
3518 bool eindent_open = false;
3519 bool foot_this_level = false;
3520 // flags when footnotetext should be appended to file.
3521 static bool minipage_open = false;
3522 static int minipage_open_depth = 0;
3523 char par_sep = bparams.paragraph_separation;
3525 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3527 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3529 LyXLayout const & style =
3530 textclasslist.Style(bparams.textclass,
3533 if (pextra_type == PEXTRA_INDENT) {
3534 if (!pextra_width.empty()) {
3535 os << "\\begin{LyXParagraphIndent}{"
3536 << pextra_width << "}\n";
3538 //float ib = atof(pextra_widthp.c_str())/100;
3539 // string can't handle floats at present (971109)
3540 // so I'll do a conversion by hand knowing that
3541 // the limits are 0.0 to 1.0. ARRae.
3542 os << "\\begin{LyXParagraphIndent}{";
3543 switch (pextra_widthp.length()) {
3555 os << "\\columnwidth}\n";
3558 eindent_open = true;
3560 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3561 if (pextra_hfill && Previous() &&
3562 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3563 os << "\\hfill{}\n";
3566 if (par_sep == BufferParams::PARSEP_INDENT) {
3567 os << "{\\setlength\\parindent{0pt}\n";
3570 os << "\\begin{minipage}";
3571 switch(pextra_alignment) {
3572 case MINIPAGE_ALIGN_TOP:
3575 case MINIPAGE_ALIGN_MIDDLE:
3578 case MINIPAGE_ALIGN_BOTTOM:
3582 if (!pextra_width.empty()) {
3583 os << '{' << pextra_width << "}\n";
3585 //float ib = atof(par->pextra_width.c_str())/100;
3586 // string can't handle floats at present
3587 // so I'll do a conversion by hand knowing that
3588 // the limits are 0.0 to 1.0. ARRae.
3590 switch (pextra_widthp.length()) {
3602 os << "\\columnwidth}\n";
3605 if (par_sep == BufferParams::PARSEP_INDENT) {
3606 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3609 minipage_open = true;
3610 minipage_open_depth = depth;
3613 #ifdef WITH_WARNINGS
3614 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3615 //I disabled it because it breaks when lists span on several
3618 if (style.isEnvironment()){
3619 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3620 #ifdef FANCY_FOOTNOTE_CODE
3621 if (foot_count < 0) {
3622 // flag that footnote[mark][text] should be
3623 // used for any footnotes from now on
3625 foot_this_level = true;
3628 os << "\\begin{" << style.latexname() << "}{"
3629 << labelwidthstring << "}\n";
3630 } else if (style.labeltype == LABEL_BIBLIO) {
3632 os << "\\begin{" << style.latexname() << "}{"
3633 << bibitemWidest(current_view->painter())
3635 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3636 #ifdef FANCY_FOOTNOTE_CODE
3637 if (foot_count < 0) {
3638 // flag that footnote[mark][text] should be
3639 // used for any footnotes from now on
3641 foot_this_level = true;
3644 os << "\\begin{" << style.latexname() << '}'
3645 << style.latexparam() << '\n';
3647 os << "\\begin{" << style.latexname() << '}'
3648 << style.latexparam() << '\n';
3651 LyXParagraph * par = this;
3653 par = par->TeXOnePar(buf, bparams,
3655 foot, foot_texrow, foot_count);
3657 if (minipage_open && par && !style.isEnvironment() &&
3658 (par->pextra_type == PEXTRA_MINIPAGE) &&
3659 par->pextra_start_minipage) {
3660 os << "\\end{minipage}\n";
3662 if (par_sep == BufferParams::PARSEP_INDENT) {
3666 minipage_open = false;
3668 if (par && par->depth > depth) {
3669 if (textclasslist.Style(bparams.textclass,
3670 par->layout).isParagraph()
3673 // How to handle this? (Lgb)
3674 //&& !suffixIs(os, "\n\n")
3676 // There should be at least one '\n' already
3677 // but we need there to be two for Standard
3678 // paragraphs that are depth-increment'ed to be
3679 // output correctly. However, tables can
3680 // also be paragraphs so don't adjust them.
3683 // Will it ever harm to have one '\n' too
3684 // many? i.e. that we sometimes will have
3685 // three in a row. (Lgb)
3689 par = par->TeXDeeper(buf, bparams, os, texrow,
3690 foot, foot_texrow, foot_count);
3692 if (par && par->layout == layout && par->depth == depth &&
3693 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3694 if (par->pextra_hfill && par->Previous() &&
3695 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3696 os << "\\hfill{}\n";
3699 if (par_sep == BufferParams::PARSEP_INDENT) {
3700 os << "{\\setlength\\parindent{0pt}\n";
3703 os << "\\begin{minipage}";
3704 switch(par->pextra_alignment) {
3705 case MINIPAGE_ALIGN_TOP:
3708 case MINIPAGE_ALIGN_MIDDLE:
3711 case MINIPAGE_ALIGN_BOTTOM:
3715 if (!par->pextra_width.empty()) {
3716 os << '{' << par->pextra_width << "}\n";
3718 //float ib = atof(par->pextra_widthp.c_str())/100;
3719 // string can't handle floats at present
3720 // so I'll do a conversion by hand knowing that
3721 // the limits are 0.0 to 1.0. ARRae.
3723 switch (par->pextra_widthp.length()) {
3728 os << "0." << par->pextra_widthp;
3731 os << "0.0" << par->pextra_widthp;
3733 os << "\\columnwidth}\n";
3736 if (par_sep == BufferParams::PARSEP_INDENT) {
3737 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3740 minipage_open = true;
3741 minipage_open_depth = par->depth;
3744 && par->layout == layout
3745 && par->depth == depth
3746 && par->pextra_type == pextra_type
3747 && par->footnoteflag == footnoteflag);
3749 if (style.isEnvironment()) {
3750 os << "\\end{" << style.latexname() << '}';
3751 // maybe this should go after the minipage closes?
3752 if (foot_this_level) {
3753 if (foot_count >= 1) {
3754 if (foot_count > 1) {
3755 os << "\\addtocounter{footnote}{-"
3760 texrow += foot_texrow;
3762 foot_texrow.reset();
3767 if (minipage_open && (minipage_open_depth == depth) &&
3768 (!par || par->pextra_start_minipage ||
3769 par->pextra_type != PEXTRA_MINIPAGE)) {
3770 os << "\\end{minipage}\n";
3772 if (par_sep == BufferParams::PARSEP_INDENT) {
3776 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3777 os << "\\medskip\n\n";
3781 minipage_open = false;
3784 os << "\\end{LyXParagraphIndent}\n";
3787 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3788 && par->pextra_hfill)) {
3792 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3793 return par; // ale970302
3798 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3799 BufferParams const & bparams,
3800 ostream & os, TexRow & texrow,
3801 ostream & foot, TexRow & foot_texrow,
3805 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3806 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3807 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3808 "No footnote!" << endl;
3810 LyXParagraph * par = this;
3811 LyXLayout const & style =
3812 textclasslist.Style(bparams.textclass,
3813 previous->GetLayout());
3815 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3816 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3817 "Float other than footnote in command"
3818 " with moving argument is illegal" << endl;
3821 if (footnotekind != LyXParagraph::FOOTNOTE
3822 && footnotekind != LyXParagraph::MARGIN
3825 // How to solve this?
3826 //&& !suffixIs(file, '\n')
3828 // we need to ensure that real floats like tables and figures
3829 // have their \begin{} on a new line otherwise we can get
3830 // incorrect results when using the endfloat.sty package
3831 // especially if two floats follow one another. ARRae 981022
3832 // NOTE: if the file is length 0 it must have just been
3833 // written out so we assume it ended with a '\n'
3835 // As far as I can see there is never any harm in writing
3836 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3841 bool moving_arg = false;
3842 bool need_closing = false;
3843 bool is_rtl = isRightToLeftPar(bparams);
3845 if (is_rtl != parent_is_rtl) {
3850 need_closing = true;
3853 //BufferParams * params = ¤t_view->buffer()->params;
3854 bool footer_in_body = true;
3855 switch (footnotekind) {
3856 case LyXParagraph::FOOTNOTE:
3857 if (style.intitle) {
3858 os << "\\thanks{\n";
3859 footer_in_body = false;
3862 if (foot_count == -1) {
3863 // we're at depth 0 so we can use:
3864 os << "\\footnote{%\n";
3865 footer_in_body = false;
3867 os << "\\footnotemark{}%\n";
3869 // we only need this when there are
3870 // multiple footnotes
3871 os << "\\stepcounter{footnote}";
3873 os << "\\footnotetext{%\n";
3874 foot_texrow.start(this, 0);
3875 foot_texrow.newline();
3880 case LyXParagraph::MARGIN:
3881 os << "\\marginpar{\n";
3883 case LyXParagraph::FIG:
3884 if (pextra_type == PEXTRA_FLOATFLT
3885 && (!pextra_width.empty()
3886 || !pextra_widthp.empty())) {
3887 if (!pextra_width.empty())
3888 os << "\\begin{floatingfigure}{"
3889 << pextra_width << "}\n";
3891 os << "\\begin{floatingfigure}{"
3892 << atoi(pextra_widthp.c_str())/100.0
3893 << "\\textwidth}\n";
3895 os << "\\begin{figure}";
3896 if (!bparams.float_placement.empty()) {
3897 os << '[' << bparams.float_placement << "]\n";
3903 case LyXParagraph::TAB:
3904 os << "\\begin{table}";
3905 if (!bparams.float_placement.empty()) {
3906 os << '[' << bparams.float_placement << "]\n";
3911 case LyXParagraph::WIDE_FIG:
3912 os << "\\begin{figure*}";
3913 if (!bparams.float_placement.empty()) {
3914 os << '[' << bparams.float_placement << "]\n";
3919 case LyXParagraph::WIDE_TAB:
3920 os << "\\begin{table*}";
3921 if (!bparams.float_placement.empty()) {
3922 os << '[' << bparams.float_placement << "]\n";
3927 case LyXParagraph::ALGORITHM:
3928 os << "\\begin{algorithm}\n";
3933 if (footnotekind != LyXParagraph::FOOTNOTE
3934 || !footer_in_body) {
3935 // Process text for all floats except footnotes in body
3937 LyXLayout const & style =
3939 .Style(bparams.textclass, par->layout);
3941 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3943 if (style.isEnvironment()
3944 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3945 // Allows the use of minipages within float
3946 // environments. Shouldn't be circular because
3947 // we don't support footnotes inside
3948 // floats (yet). ARRae
3949 par = par->TeXEnvironment(buf, bparams, os,
3954 par = par->TeXOnePar(buf, bparams,
3955 os, texrow, moving_arg,
3960 if (par && !par->IsDummy() && par->depth > depth) {
3961 par = par->TeXDeeper(buf, bparams, os, texrow,
3965 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3967 // process footnotes > depth 0 or in environments separately
3968 // NOTE: Currently don't support footnotes within footnotes
3969 // even though that is possible using the \footnotemark
3971 std::ostringstream dummy;
3975 TexRow dummy_texrow;
3976 int dummy_count = 0;
3978 LyXLayout const & style =
3980 .Style(bparams.textclass, par->layout);
3982 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3984 if (style.isEnvironment()
3985 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3986 // Allows the use of minipages within float
3987 // environments. Shouldn't be circular because
3988 // we don't support footnotes inside
3989 // floats (yet). ARRae
3990 par = par->TeXEnvironment(buf, bparams,
3992 dummy, dummy_texrow,
3995 par = par->TeXOnePar(buf, bparams,
3998 dummy, dummy_texrow,
4002 if (par && !par->IsDummy() && par->depth > depth) {
4003 par = par->TeXDeeper(buf, bparams,
4005 dummy, dummy_texrow,
4009 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4011 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4012 "Footnote in a Footnote -- not supported"
4015 #ifndef HAVE_OSTREAM
4016 delete [] dummy.str();
4020 switch (footnotekind) {
4021 case LyXParagraph::FOOTNOTE:
4022 if (footer_in_body) {
4023 // This helps tell which of the multiple
4024 // footnotetexts an error was in.
4026 foot_texrow.newline();
4031 case LyXParagraph::MARGIN:
4034 case LyXParagraph::FIG:
4035 if (pextra_type == PEXTRA_FLOATFLT
4036 && (!pextra_width.empty()
4037 || !pextra_widthp.empty()))
4038 os << "\\end{floatingfigure}";
4040 os << "\\end{figure}";
4042 case LyXParagraph::TAB:
4043 os << "\\end{table}";
4045 case LyXParagraph::WIDE_FIG:
4046 os << "\\end{figure*}";
4048 case LyXParagraph::WIDE_TAB:
4049 os << "\\end{table*}";
4051 case LyXParagraph::ALGORITHM:
4052 os << "\\end{algorithm}";
4059 if (footnotekind != LyXParagraph::FOOTNOTE
4060 && footnotekind != LyXParagraph::MARGIN) {
4061 // we need to ensure that real floats like tables and figures
4062 // have their \end{} on a line of their own otherwise we can
4063 // get incorrect results when using the endfloat.sty package.
4068 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4073 bool LyXParagraph::IsDummy() const
4075 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4076 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4080 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4081 int type, char const * width,
4082 char const * widthp)
4085 pextra_width = width;
4086 pextra_widthp = widthp;
4088 if (textclasslist.Style(bparams.textclass,
4089 layout).isEnvironment()) {
4094 while (par && (par->layout == layout)
4095 && (par->depth == depth)) {
4097 par = par->Previous();
4099 par = par->FirstPhysicalPar();
4100 while (par && par->depth > depth) {
4101 par = par->Previous();
4103 par = par->FirstPhysicalPar();
4107 while (par && (par->layout == layout)
4108 && (par->depth == depth)) {
4109 par->pextra_type = type;
4110 par->pextra_width = width;
4111 par->pextra_widthp = widthp;
4112 par = par->NextAfterFootnote();
4113 if (par && (par->depth > depth))
4114 par->SetPExtraType(bparams,
4115 type, width, widthp);
4116 while (par && ((par->depth > depth) || par->IsDummy()))
4117 par = par->NextAfterFootnote();
4123 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4125 if (pextra_type == PEXTRA_NONE)
4128 pextra_type = PEXTRA_NONE;
4129 pextra_width.erase();
4130 pextra_widthp.erase();
4132 if (textclasslist.Style(bparams.textclass,
4133 layout).isEnvironment()) {
4138 while (par && (par->layout == layout)
4139 && (par->depth == depth)) {
4141 par = par->Previous();
4143 par = par->FirstPhysicalPar();
4144 while (par && par->depth > depth) {
4145 par = par->Previous();
4147 par = par->FirstPhysicalPar();
4151 while (par && (par->layout == layout)
4152 && (par->depth == depth)) {
4153 par->pextra_type = PEXTRA_NONE;
4154 par->pextra_width.erase();
4155 par->pextra_widthp.erase();
4156 par = par->NextAfterFootnote();
4157 if (par && (par->depth > depth))
4158 par->UnsetPExtraType(bparams);
4159 while (par && ((par->depth > depth) || par->IsDummy()))
4160 par = par->NextAfterFootnote();
4166 bool LyXParagraph::IsHfill(size_type pos) const
4168 return IsHfillChar(GetChar(pos));
4172 bool LyXParagraph::IsInset(size_type pos) const
4174 return IsInsetChar(GetChar(pos));
4178 bool LyXParagraph::IsFloat(size_type pos) const
4180 return IsFloatChar(GetChar(pos));
4184 bool LyXParagraph::IsNewline(size_type pos) const
4186 return pos >= 0 && IsNewlineChar(GetChar(pos));
4190 bool LyXParagraph::IsSeparator(size_type pos) const
4192 return IsSeparatorChar(GetChar(pos));
4196 bool LyXParagraph::IsLineSeparator(size_type pos) const
4198 return IsLineSeparatorChar(GetChar(pos));
4202 bool LyXParagraph::IsKomma(size_type pos) const
4204 return IsKommaChar(GetChar(pos));
4208 /// Used by the spellchecker
4209 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4211 unsigned char c = GetChar(pos);
4212 if (IsLetterChar(c))
4214 // '\0' is not a letter, allthough every string contains "" (below)
4217 // We want to pass the ' and escape chars to ispell
4218 string extra = lyxrc.isp_esc_chars + '\'';
4222 return contains(extra, ch);
4226 bool LyXParagraph::IsWord(size_type pos ) const
4228 return IsWordChar(GetChar(pos)) ;
4233 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4236 return FirstPhysicalPar()->getParLanguage(bparams);
4237 else if (size() > 0)
4241 return GetFirstFontSettings().language();
4244 for (size_type pos = 0; pos < size(); ++pos)
4246 return GetFontSettings(bparams, pos).language();
4247 return GetFirstFontSettings().language();
4251 return previous->getParLanguage(bparams);
4253 return bparams.language_info;
4257 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4259 return lyxrc.rtl_support && !table
4260 && getParLanguage(bparams)->RightToLeft();
4264 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4265 Language const * from, Language const * to)
4267 for(size_type i = 0; i < size(); ++i) {
4268 LyXFont font = GetFontSettings(bparams, i);
4269 if (font.language() == from) {
4270 font.setLanguage(to);
4277 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4279 Language const * doc_language =
4280 bparams.language_info;
4281 for(size_type i = 0; i < size(); ++i) {
4282 LyXFont font = GetFontSettings(bparams, i);
4283 if (font.language() != doc_language)
4290 // Convert the paragraph to a string.
4291 // Used for building the table of contents
4292 string LyXParagraph::String(Buffer const * buffer, bool label)
4294 BufferParams const & bparams = buffer->params;
4296 if (label && !IsDummy() && !labelstring.empty())
4297 s += labelstring + ' ';
4298 string::size_type len = s.size();
4300 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4301 unsigned char c = GetChar(i);
4304 else if (c == META_INSET &&
4305 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4307 std::ostringstream ost;
4308 GetInset(i)->Ascii(buffer, ost);
4311 GetInset(i)->Ascii(buffer, ost);
4314 s += subst(ost.str(),'\n',' ');
4319 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4320 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4321 s += NextAfterFootnote()->String(buffer, false);
4326 if (isRightToLeftPar(bparams))
4327 reverse(s.begin() + len,s.end());
4333 string LyXParagraph::String(Buffer const * buffer,
4334 LyXParagraph::size_type beg,
4335 LyXParagraph::size_type end)
4342 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4344 if (cell >= table->NumberOfCellsInRow(actcell))
4352 if (beg == 0 && !IsDummy() && !labelstring.empty())
4353 s += labelstring + ' ';
4355 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4356 unsigned char c = GetChar(i);
4359 else if (c == META_INSET) {
4361 std::ostringstream ost;
4362 GetInset(i)->Ascii(buffer, ost);
4365 GetInset(i)->Ascii(buffer, ost);
4369 } else if (table && IsNewlineChar(c)) {
4370 if (cell >= table->NumberOfCellsInRow(actcell)) {
4381 //if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4382 // s += NextAfterFootnote()->String(false);
4388 void LyXParagraph::SetInsetOwner(Inset *i)
4391 for (InsetList::const_iterator cit = insetlist.begin();
4392 cit != insetlist.end(); ++cit) {
4394 (*cit).inset->setOwner(i);
4399 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4402 for (InsetList::const_iterator cit = insetlist.begin();
4403 cit != insetlist.end(); ++cit) {
4405 if ((*cit).inset->IsTextInset()) {
4406 static_cast<InsetText *>((*cit).inset)->