1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
25 #include "tex-strings.h"
27 #include "bufferparams.h"
28 #include "support/FileInfo.h"
29 #include "support/LAssert.h"
31 #include "LaTeXFeatures.h"
32 #include "insets/insetinclude.h"
33 #include "insets/insetbib.h"
34 #include "insets/insettext.h"
35 #include "support/filetools.h"
36 #include "lyx_gui_misc.h"
38 #include "support/lyxmanip.h"
39 #include "BufferView.h"
46 using std::lower_bound;
47 using std::upper_bound;
50 int tex_code_break_column = 72; // needs non-zero initialization. set later.
51 // this is a bad idea, but how can LyXParagraph find its buffer to get
52 // parameters? (JMarc)
53 extern BufferView * current_view;
54 extern string bibitemWidest(BufferView *);
56 // this is a minibuffer
57 static char minibuffer_char;
58 static LyXFont minibuffer_font;
59 static Inset * minibuffer_inset;
62 // Initialization of the counter for the paragraph id's,
63 // declared in lyxparagraph.h
64 unsigned int LyXParagraph::paragraph_id = 0;
67 LyXParagraph::LyXParagraph()
69 text.reserve(500); // is this number too big?
71 for (int i = 0; i < 10; ++i) setCounter(i , 0);
78 footnoteflag = LyXParagraph::NO_FOOTNOTE;
79 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
81 align = LYX_ALIGN_BLOCK;
84 /* table stuff -- begin*/
86 /* table stuff -- end*/
90 bibkey = 0; // ale970302
95 // This konstruktor inserts the new paragraph in a list.
96 LyXParagraph::LyXParagraph(LyXParagraph * par)
99 par->text.resize(par->text.size());
101 for (int i = 0; i < 10; ++i) setCounter(i, 0);
105 // double linked list begin
108 next->previous = this;
110 previous->next = this;
113 footnoteflag = LyXParagraph::NO_FOOTNOTE;
114 footnotekind = LyXParagraph::FOOTNOTE;
117 /* table stuff -- begin*/
119 /* table stuff -- end*/
122 id_ = paragraph_id++;
124 bibkey = 0; // ale970302
130 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
131 BufferParams const & params,
132 char footflag, char dth) const
136 footnoteflag != LyXParagraph::NO_FOOTNOTE ||
138 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
143 // The beginning or the end of a footnote environment?
144 if (footflag != footnoteflag) {
145 footflag = footnoteflag;
147 os << "\n\\begin_float "
148 << string_footnotekinds[footnotekind]
151 os << "\n\\end_float ";
155 // The beginning or end of a deeper (i.e. nested) area?
158 while (depth > dth) {
159 os << "\n\\begin_deeper ";
163 while (depth < dth) {
164 os << "\n\\end_deeper ";
170 // First write the layout
172 << textclasslist.NameOfLayout(params.textclass, layout)
175 // Maybe some vertical spaces.
176 if (added_space_top.kind() != VSpace::NONE)
177 os << "\\added_space_top "
178 << added_space_top.asLyXCommand() << " ";
179 if (added_space_bottom.kind() != VSpace::NONE)
180 os << "\\added_space_bottom "
181 << added_space_bottom.asLyXCommand() << " ";
183 // Maybe the paragraph has special spacing
184 spacing.writeFile(os, true);
186 // The labelwidth string used in lists.
187 if (!labelwidthstring.empty())
188 os << "\\labelwidthstring "
189 << labelwidthstring << '\n';
191 // Lines above or below?
195 os << "\\line_bottom ";
197 // Pagebreaks above or below?
199 os << "\\pagebreak_top ";
200 if (pagebreak_bottom)
201 os << "\\pagebreak_bottom ";
203 // Start of appendix?
204 if (start_of_appendix)
205 os << "\\start_of_appendix ";
212 if (align != LYX_ALIGN_LAYOUT) {
215 case LYX_ALIGN_LEFT: h = 1; break;
216 case LYX_ALIGN_RIGHT: h = 2; break;
217 case LYX_ALIGN_CENTER: h = 3; break;
218 default: h = 0; break;
220 os << "\\align " << string_align[h] << " ";
222 if (pextra_type != PEXTRA_NONE) {
223 os << "\\pextra_type " << pextra_type;
224 if (pextra_type == PEXTRA_MINIPAGE) {
225 os << " \\pextra_alignment "
228 os << " \\pextra_hfill "
230 if (pextra_start_minipage)
231 os << " \\pextra_start_minipage "
232 << pextra_start_minipage;
234 if (!pextra_width.empty()) {
235 os << " \\pextra_width "
236 << VSpace(pextra_width).asLyXCommand();
237 } else if (!pextra_widthp.empty()) {
238 os << " \\pextra_widthp "
245 // Dummy layout. This means that a footnote ended.
246 os << "\n\\end_float ";
247 footflag = LyXParagraph::NO_FOOTNOTE;
251 // It might be a table.
253 os << "\\LyXTable\n";
259 bibkey->Write(buf, os);
261 LyXFont font1(LyXFont::ALL_INHERIT, params.language_info);
264 for (size_type i = 0; i < size(); ++i) {
270 // Write font changes
271 LyXFont font2 = GetFontSettings(params, i);
272 if (font2 != font1) {
273 font2.lyxWriteChanges(font1, os);
278 value_type c = GetChar(i);
282 Inset const * inset = GetInset(i);
284 if (inset->DirectWrite()) {
285 // international char, let it write
286 // code directly so it's shorter in
288 inset->Write(buf, os);
290 os << "\n\\begin_inset ";
291 inset->Write(buf, os);
292 os << "\n\\end_inset \n\n";
298 os << "\n\\newline \n";
302 os << "\n\\hfill \n";
306 os << "\n\\backslash \n";
310 if (i + 1 < size() && GetChar(i + 1) == ' ') {
317 if ((column > 70 && c == ' ')
322 // this check is to amend a bug. LyX sometimes
323 // inserts '\0' this could cause problems.
327 lyxerr << "ERROR (LyXParagraph::writeFile):"
328 " NULL char in structure." << endl;
334 // now write the next paragraph
336 next->writeFile(buf, os, params, footflag, dth);
340 void LyXParagraph::validate(LaTeXFeatures & features) const
342 BufferParams const & params = features.bufferParams();
345 // this will be useful later
346 LyXLayout const & layout =
347 textclasslist.Style(params.textclass,
352 if (line_top || line_bottom)
353 features.lyxline = true;
354 if (!spacing.isDefault())
355 features.setspace = true;
358 features.layout[GetLayout()] = true;
361 Language const * doc_language = params.language_info;
363 for (FontList::const_iterator cit = fontlist.begin();
364 cit != fontlist.end(); ++cit) {
365 if ((*cit).font.noun() == LyXFont::ON) {
366 lyxerr[Debug::LATEX] << "font.noun: "
367 << (*cit).font.noun()
369 features.noun = true;
370 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
371 << (*cit).font.stateText(0)
374 switch ((*cit).font.color()) {
376 case LColor::inherit:
380 features.color = true;
381 lyxerr[Debug::LATEX] << "Color enabled. Font: "
382 << (*cit).font.stateText(0)
386 Language const * language = (*cit).font.language();
387 if (language != doc_language) {
388 features.UsedLanguages.insert(language);
389 lyxerr[Debug::LATEX] << "Found language "
390 << language->lang() << endl;
395 for (InsetList::const_iterator cit = insetlist.begin();
396 cit != insetlist.end(); ++cit) {
398 (*cit).inset->Validate(features);
402 if (table && table->IsLongTable())
403 features.longtable = true;
405 if (pextra_type == PEXTRA_INDENT)
406 features.LyXParagraphIndent = true;
407 if (pextra_type == PEXTRA_FLOATFLT)
408 features.floatflt = true;
410 if (layout.needprotect
411 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
412 features.NeedLyXFootnoteCode = true;
414 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
415 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
416 features.NeedLyXMinipageIndent = true;
418 if (table && table->NeedRotating())
419 features.rotating = true;
422 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
423 features.algorithm = true;
428 // First few functions needed for cut and paste and paragraph breaking.
429 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
430 LyXParagraph::size_type pos) const
432 minibuffer_char = GetChar(pos);
433 minibuffer_font = GetFontSettings(bparams, pos);
434 minibuffer_inset = 0;
435 if (minibuffer_char == LyXParagraph::META_INSET) {
437 minibuffer_inset = GetInset(pos)->Clone();
439 minibuffer_inset = 0;
440 minibuffer_char = ' ';
441 // This reflects what GetInset() does (ARRae)
447 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
448 LyXParagraph::size_type pos)
450 minibuffer_char = GetChar(pos);
451 minibuffer_font = GetFontSettings(bparams, pos);
452 minibuffer_inset = 0;
453 if (minibuffer_char == LyXParagraph::META_INSET) {
455 minibuffer_inset = GetInset(pos);
456 // This is a little hack since I want exactly
457 // the inset, not just a clone. Otherwise
458 // the inset would be deleted when calling Erase(pos)
460 InsetTable search_elem(pos, 0);
461 InsetList::iterator it =
462 lower_bound(insetlist.begin(),
464 search_elem, matchIT());
465 if (it != insetlist.end() && (*it).pos == pos)
468 minibuffer_inset = 0;
469 minibuffer_char = ' ';
470 // This reflects what GetInset() does (ARRae)
475 // Erase(pos); now the caller is responsible for that.
479 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
481 if ((minibuffer_char == LyXParagraph::META_INSET) &&
482 !InsertInsetAllowed(minibuffer_inset))
484 if (minibuffer_char == LyXParagraph::META_INSET)
485 InsertInset(pos, minibuffer_inset, minibuffer_font);
487 InsertChar(pos, minibuffer_char, minibuffer_font);
495 void LyXParagraph::Clear()
500 pagebreak_top = false;
501 pagebreak_bottom = false;
503 added_space_top = VSpace(VSpace::NONE);
504 added_space_bottom = VSpace(VSpace::NONE);
505 spacing.set(Spacing::Default);
507 align = LYX_ALIGN_LAYOUT;
511 pextra_type = PEXTRA_NONE;
512 pextra_width.erase();
513 pextra_widthp.erase();
514 pextra_alignment = MINIPAGE_ALIGN_TOP;
515 pextra_hfill = false;
516 pextra_start_minipage = false;
519 labelwidthstring.erase();
523 start_of_appendix = false;
527 // the destructor removes the new paragraph from the list
528 LyXParagraph::~LyXParagraph()
531 previous->next = next;
533 next->previous = previous;
535 for (InsetList::iterator it = insetlist.begin();
536 it != insetlist.end(); ++it) {
540 /* table stuff -- begin*/
542 /* table stuff -- end*/
548 //lyxerr << "LyXParagraph::paragraph_id = "
549 // << LyXParagraph::paragraph_id << endl;
553 void LyXParagraph::Erase(LyXParagraph::size_type pos)
556 // > because last is the next unused position, and you can
557 // use it if you want
559 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
560 NextAfterFootnote()->Erase(pos - text.size() - 1);
562 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
563 "position does not exist." << endl;
567 Assert(pos < size());
570 if (pos < size()) { // last is free for insertation, but should be empty
572 // if it is an inset, delete the inset entry
573 if (text[pos] == LyXParagraph::META_INSET) {
575 InsetTable search_inset(pos, 0);
576 InsetList::iterator it =
577 lower_bound(insetlist.begin(),
579 search_inset, matchIT());
580 if (it != insetlist.end() && (*it).pos == pos) {
585 text.erase(text.begin() + pos);
587 // Erase entries in the tables.
588 FontTable search_font(pos, LyXFont());
590 FontList::iterator it =
591 lower_bound(fontlist.begin(),
593 search_font, matchFT());
594 if (it != fontlist.end() && (*it).pos == pos &&
596 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
597 // If it is a multi-character font
598 // entry, we just make it smaller
599 // (see update below), otherwise we
601 unsigned int i = it - fontlist.begin();
602 fontlist.erase(fontlist.begin() + i);
603 it = fontlist.begin() + i;
604 if (i > 0 && i < fontlist.size() &&
605 fontlist[i-1].font == fontlist[i].font) {
606 fontlist.erase(fontlist.begin() + i-1);
607 it = fontlist.begin() + i-1;
611 // Update all other entries.
612 for (; it != fontlist.end(); ++it)
615 // Update the inset table.
616 InsetTable search_inset(pos, 0);
617 for (InsetList::iterator it =
618 upper_bound(insetlist.begin(),
620 search_inset, matchIT());
621 it != insetlist.end(); ++it)
625 lyxerr << "ERROR (LyXParagraph::Erase): "
626 "can't erase non-existant char." << endl;
632 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
633 LyXParagraph::value_type c)
635 LyXFont f(LyXFont::ALL_INHERIT);
636 InsertChar(pos, c, f);
640 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
641 LyXParagraph::value_type c,
642 LyXFont const & font)
645 // > because last is the next unused position, and you can
646 // use it if you want
649 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
650 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
653 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
654 "position does not exist." << endl;
658 Assert(pos <= size());
660 text.insert(text.begin() + pos, c);
661 // Update the font table.
662 FontTable search_font(pos, LyXFont());
663 for (FontList::iterator it = lower_bound(fontlist.begin(),
665 search_font, matchFT());
666 it != fontlist.end(); ++it)
669 // Update the inset table.
670 InsetTable search_inset(pos, 0);
671 for (InsetList::iterator it = lower_bound(insetlist.begin(),
673 search_inset, matchIT());
674 it != insetlist.end(); ++it)
681 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
684 LyXFont f(LyXFont::ALL_INHERIT);
685 InsertInset(pos, inset, f);
689 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
690 Inset * inset, LyXFont const & font)
695 // > because last is the next unused position, and you can
696 // use it if you want
699 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
701 ->InsertInset(pos - text.size() - 1,
704 lyxerr << "ERROR (LyXParagraph::InsertInset): "
705 "position does not exist: " << pos << endl;
709 Assert(pos <= size());
712 InsertChar(pos, META_INSET, font);
713 Assert(text[pos] == META_INSET);
715 // Add a new entry in the inset table.
716 InsetTable search_inset(pos, 0);
717 InsetList::iterator it = lower_bound(insetlist.begin(),
719 search_inset, matchIT());
720 if (it != insetlist.end() && (*it).pos == pos)
721 lyxerr << "ERROR (LyXParagraph::InsertInset): "
722 "there is an inset in position: " << pos << endl;
724 insetlist.insert(it, InsetTable(pos, inset));
726 inset->setOwner(inset_owner);
730 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
732 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
735 return inset_owner->InsertInsetAllowed(inset);
740 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
745 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
746 return NextAfterFootnote()
747 ->GetInset(pos - text.size() - 1);
749 lyxerr << "ERROR (LyXParagraph::GetInset): "
750 "position does not exist: "
756 Assert(pos < size());
759 InsetTable search_inset(pos, 0);
760 InsetList::iterator it = lower_bound(insetlist.begin(),
762 search_inset, matchIT());
763 if (it != insetlist.end() && (*it).pos == pos)
766 lyxerr << "ERROR (LyXParagraph::GetInset): "
767 "Inset does not exist: " << pos << endl;
770 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
771 // Did this commenting out introduce a bug? So far I have not
772 // see any, please enlighten me. (Lgb)
773 // My guess is that since the inset does not exist, we might
774 // as well replace it with a space to prevent craches. (Asger)
779 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
784 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
785 return NextAfterFootnote()
786 ->GetInset(pos - text.size() - 1);
788 lyxerr << "ERROR (LyXParagraph::GetInset): "
789 "position does not exist: "
795 Assert(pos < size());
798 InsetTable search_inset(pos, 0);
799 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
801 search_inset, matchIT());
802 if (cit != insetlist.end() && (*cit).pos == pos)
805 lyxerr << "ERROR (LyXParagraph::GetInset): "
806 "Inset does not exist: " << pos << endl;
808 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
809 // Did this commenting out introduce a bug? So far I have not
810 // see any, please enlighten me. (Lgb)
811 // My guess is that since the inset does not exist, we might
812 // as well replace it with a space to prevent craches. (Asger)
817 // Gets uninstantiated font setting at position.
818 // Optimized after profiling. (Asger)
819 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
820 LyXParagraph::size_type pos) const
823 Assert(pos <= size());
828 FontTable search_font(pos, LyXFont());
829 FontList::const_iterator cit = lower_bound(fontlist.begin(),
831 search_font, matchFT());
832 if (cit != fontlist.end())
838 // > because last is the next unused position, and you can
839 // use it if you want
840 else if (pos > size()) {
842 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
843 return NextAfterFootnote()
844 ->GetFontSettings(bparams,
845 pos - text.size() - 1);
847 // Why is it an error to ask for the font of a
848 // position that does not exist? Would it be
849 // enough for this to be enabled on debug?
850 // We want strict error checking, but it's ok to only
851 // have it when debugging. (Asger)
852 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
853 "position does not exist. "
854 << pos << " (" << static_cast<int>(pos)
858 return GetFontSettings(bparams, pos - 1);
861 if (pos == size() && size())
862 return GetFontSettings(bparams, pos - 1);
866 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
868 //return LyXFont(LyXFont::ALL_INHERIT);
871 // Gets uninstantiated font setting at position 0
872 LyXFont LyXParagraph::GetFirstFontSettings() const
875 if (!fontlist.empty())
876 return fontlist[0].font;
880 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
881 return NextAfterFootnote()->GetFirstFontSettings();
883 return LyXFont(LyXFont::ALL_INHERIT);
887 // Gets the fully instantiated font at a given position in a paragraph
888 // This is basically the same function as LyXText::GetFont() in text2.C.
889 // The difference is that this one is used for generating the LaTeX file,
890 // and thus cosmetic "improvements" are disallowed: This has to deliver
891 // the true picture of the buffer. (Asger)
892 // If position is -1, we get the layout font of the paragraph.
893 // If position is -2, we get the font of the manual label of the paragraph.
894 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
895 LyXParagraph::size_type pos) const
898 LyXLayout const & layout =
899 textclasslist.Style(bparams.textclass,
901 LyXParagraph::size_type main_body = 0;
902 if (layout.labeltype == LABEL_MANUAL)
903 main_body = BeginningOfMainBody();
908 layoutfont = layout.labelfont;
910 layoutfont = layout.font;
911 tmpfont = GetFontSettings(bparams, pos);
912 tmpfont.realize(layoutfont);
914 // process layoutfont for pos == -1 and labelfont for pos < -1
916 tmpfont = layout.font;
918 tmpfont = layout.labelfont;
919 tmpfont.setLanguage(getParLanguage(bparams));
922 // check for environment font information
923 char par_depth = GetDepth();
924 LyXParagraph const * par = this;
925 while (par && par_depth && !tmpfont.resolved()) {
926 par = par->DepthHook(par_depth - 1);
928 tmpfont.realize(textclasslist.
929 Style(bparams.textclass,
930 par->GetLayout()).font);
931 par_depth = par->GetDepth();
935 tmpfont.realize(textclasslist
936 .TextClass(bparams.textclass)
942 /// Returns the height of the highest font in range
944 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
945 LyXParagraph::size_type endpos) const
947 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
948 if (fontlist.empty())
951 FontTable end_search(endpos, LyXFont());
952 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
954 end_search, matchFT());
955 if (end_it != fontlist.end())
958 FontTable start_search(startpos, LyXFont());
959 for (FontList::const_iterator cit =
960 lower_bound(fontlist.begin(),
962 start_search, matchFT());
963 cit != end_it; ++cit) {
964 LyXFont::FONT_SIZE size = (*cit).font.size();
965 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
972 LyXParagraph::value_type
973 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
978 Assert(pos <= size());
979 if (!size() || pos == size()) return '\0';
990 // > because last is the next unused position, and you can
991 // use it if you want
992 else if (pos > size()) {
993 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
994 return NextAfterFootnote()
995 ->GetChar(pos - text.size() - 1);
998 lyxerr << "ERROR (LyXParagraph::GetChar const): "
999 "position does not exist."
1000 << pos << " (" << static_cast<int>(pos)
1006 // We should have a footnote environment.
1007 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1008 // Notice that LyX does request the
1009 // last char from time to time. (Asger)
1010 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1011 // "expected footnote." << endl;
1014 switch (next->footnotekind) {
1015 case LyXParagraph::FOOTNOTE:
1016 return LyXParagraph::META_FOOTNOTE;
1017 case LyXParagraph::MARGIN:
1018 return LyXParagraph::META_MARGIN;
1019 case LyXParagraph::FIG:
1020 case LyXParagraph::WIDE_FIG:
1021 return LyXParagraph::META_FIG;
1022 case LyXParagraph::TAB:
1023 case LyXParagraph::WIDE_TAB:
1024 return LyXParagraph::META_TAB;
1025 case LyXParagraph::ALGORITHM:
1026 return LyXParagraph::META_ALGORITHM;
1028 return '\0'; // to shut up gcc
1034 // return an string of the current word, and the end of the word in lastpos.
1035 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1037 Assert(lastpos >= 0);
1039 // the current word is defined as starting at the first character
1040 // from the immediate left of lastpospos which meets the definition
1041 // of IsLetter(), continuing to the last character to the right
1042 // of this meeting IsLetter.
1048 // move back until we have a letter
1050 //there's no real reason to have firstpos & lastpos as
1051 //separate variables as this is written, but maybe someon
1052 // will want to return firstpos in the future.
1054 //since someone might have typed a punctuation first
1055 int firstpos = lastpos;
1057 while ((firstpos >= 0) && !IsLetter(firstpos))
1060 // now find the beginning by looking for a nonletter
1062 while ((firstpos>= 0) && IsLetter(firstpos))
1065 // the above is now pointing to the preceeding non-letter
1069 // so copy characters into theword until we get a nonletter
1070 // note that this can easily exceed lastpos, wich means
1071 // that if used in the middle of a word, the whole word
1074 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1082 #warning Remember to get rid of this one. (Lgb)
1084 LyXParagraph::size_type LyXParagraph::Last() const
1087 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1088 return text.size() + NextAfterFootnote()->Last() + 1;
1089 // the 1 is the symbol
1098 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1100 // > because last is the next unused position, and you can
1101 // use it if you want
1104 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1105 return NextAfterFootnote()
1106 ->ParFromPos(pos - text.size() - 1);
1108 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1109 "position does not exist." << endl;
1118 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1120 // > because last is the next unused position, and you can
1121 // use it if you want
1124 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1125 return NextAfterFootnote()
1126 ->PositionInParFromPos(pos - text.size() - 1);
1129 "ERROR (LyXParagraph::PositionInParFromPos): "
1130 "position does not exist." << endl;
1139 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1140 LyXFont const & font)
1143 // > because last is the next unused position, and you can
1144 // use it if you want
1147 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1148 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1151 lyxerr << "ERROR (LyXParagraph::SetFont): "
1152 "position does not exist." << endl;
1157 Assert(pos <= size());
1160 // First, reduce font against layout/label font
1161 // Update: The SetCharFont() routine in text2.C already
1162 // reduces font, so we don't need to do that here. (Asger)
1163 // No need to simplify this because it will disappear
1164 // in a new kernel. (Asger)
1165 // Next search font table
1167 FontTable search_font(pos, LyXFont());
1168 FontList::iterator it = lower_bound(fontlist.begin(),
1170 search_font, matchFT());
1171 unsigned int i = it - fontlist.begin();
1172 bool notfound = it == fontlist.end();
1174 if (!notfound && fontlist[i].font == font)
1177 bool begin = pos == 0 || notfound ||
1178 (i > 0 && fontlist[i-1].pos == pos - 1);
1179 // Is position pos is a beginning of a font block?
1180 bool end = !notfound && fontlist[i].pos == pos;
1181 // Is position pos is the end of a font block?
1182 if (begin && end) { // A single char block
1183 if (i+1 < fontlist.size() &&
1184 fontlist[i+1].font == font) {
1185 // Merge the singleton block with the next block
1186 fontlist.erase(fontlist.begin() + i);
1187 if (i > 0 && fontlist[i-1].font == font)
1188 fontlist.erase(fontlist.begin() + i-1);
1189 } else if (i > 0 && fontlist[i-1].font == font) {
1190 // Merge the singleton block with the previous block
1191 fontlist[i-1].pos = pos;
1192 fontlist.erase(fontlist.begin() + i);
1194 fontlist[i].font = font;
1196 if (i > 0 && fontlist[i-1].font == font)
1197 fontlist[i-1].pos = pos;
1199 fontlist.insert(fontlist.begin() + i,
1200 FontTable(pos, font));
1202 fontlist[i].pos = pos - 1;
1203 if (!(i+1 < fontlist.size() &&
1204 fontlist[i+1].font == font))
1205 fontlist.insert(fontlist.begin() + i+1,
1206 FontTable(pos, font));
1207 } else { // The general case. The block is splitted into 3 blocks
1208 fontlist.insert(fontlist.begin() + i,
1209 FontTable(pos - 1, fontlist[i].font));
1210 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1215 // This function is able to hide closed footnotes.
1216 LyXParagraph * LyXParagraph::Next()
1219 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1220 LyXParagraph * tmp = next;
1222 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1224 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1225 return tmp->Next(); /* there can be more than one
1226 footnote in a logical
1229 return next; // This should never happen!
1237 LyXParagraph * LyXParagraph::NextAfterFootnote()
1239 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1240 LyXParagraph * tmp = next;
1241 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1243 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1244 return tmp; /* there can be more than one footnote
1245 in a logical paragraph */
1247 return next; // This should never happen!
1255 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1257 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1258 LyXParagraph * tmp = next;
1259 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
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 next; // This should never happen!
1273 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1276 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1278 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1279 tmp = tmp->previous;
1280 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1281 return tmp; /* there can be more than one footnote
1282 in a logical paragraph */
1284 return previous; // This should never happen!
1292 LyXParagraph * LyXParagraph::LastPhysicalPar()
1294 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1297 LyXParagraph * tmp = this;
1299 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1300 tmp = tmp->NextAfterFootnote();
1308 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1310 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1313 LyXParagraph const * tmp = this;
1315 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1316 tmp = tmp->NextAfterFootnote();
1324 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1328 LyXParagraph * tmppar = this;
1332 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1333 tmppar = tmppar->previous;
1344 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1348 LyXParagraph const * tmppar = this;
1352 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1353 tmppar = tmppar->previous;
1363 // This function is able to hide closed footnotes.
1364 LyXParagraph * LyXParagraph::Previous()
1367 LyXParagraph * tmp = previous;
1372 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1373 tmp = tmp->previous;
1375 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1376 tmp = tmp->previous;
1377 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1378 return tmp->next->Previous();
1388 // This function is able to hide closed footnotes.
1389 LyXParagraph const * LyXParagraph::Previous() const
1392 LyXParagraph * tmp = previous;
1396 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1397 tmp = tmp->previous;
1399 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1400 tmp = tmp->previous;
1401 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1402 return tmp->next->Previous();
1412 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1413 LyXParagraph::size_type pos,
1418 // create a new paragraph
1421 size_type pos_first;
1422 LyXParagraph * par = ParFromPos(pos);
1423 LyXParagraph * firstpar = FirstPhysicalPar();
1425 LyXParagraph * tmp = new LyXParagraph(par);
1427 //LyXParagraph * par = this;
1428 //LyXParagraph * firstpar = this;
1429 LyXParagraph * tmp = new LyXParagraph(this);
1433 tmp->footnoteflag = footnoteflag;
1434 tmp->footnotekind = footnotekind;
1436 // this is an idea for a more userfriendly layout handling, I will
1437 // see what the users say
1440 // layout stays the same with latex-environments
1442 tmp->SetOnlyLayout(bparams, firstpar->layout);
1443 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1446 // layout stays the same with latex-environments
1448 tmp->SetOnlyLayout(bparams, layout);
1449 tmp->SetLabelWidthString(labelwidthstring);
1453 if (Last() > pos || !Last() || flag == 2) {
1454 tmp->SetOnlyLayout(bparams, firstpar->layout);
1455 tmp->align = firstpar->align;
1456 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1458 tmp->line_bottom = firstpar->line_bottom;
1459 firstpar->line_bottom = false;
1460 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1461 firstpar->pagebreak_bottom = false;
1462 tmp->added_space_bottom = firstpar->added_space_bottom;
1463 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1465 tmp->depth = firstpar->depth;
1466 tmp->noindent = firstpar->noindent;
1468 if (Last() > pos || !Last() || flag == 2) {
1469 tmp->SetOnlyLayout(bparams, layout);
1471 tmp->SetLabelWidthString(labelwidthstring);
1473 tmp->line_bottom = line_bottom;
1474 line_bottom = false;
1475 tmp->pagebreak_bottom = pagebreak_bottom;
1476 pagebreak_bottom = false;
1477 tmp->added_space_bottom = added_space_bottom;
1478 added_space_bottom = VSpace(VSpace::NONE);
1481 tmp->noindent = noindent;
1483 // copy everything behind the break-position
1484 // to the new paragraph
1487 while (ParFromPos(pos_first) != par)
1489 pos_end = pos_first + par->text.size() - 1;
1492 for (i = j = pos; i <= pos_end; ++i) {
1493 par->CutIntoMinibuffer(bparams, i - pos_first);
1494 if (tmp->InsertFromMinibuffer(j - pos))
1497 tmp->text.resize(tmp->text.size());
1498 for (i = pos_end; i >= pos; --i)
1499 par->Erase(i - pos_first);
1501 par->text.resize(par->text.size());
1503 size_type pos_end = text.size() - 1;
1505 for (i = j = pos; i <= pos_end; ++i) {
1506 CutIntoMinibuffer(bparams, i);
1507 if (tmp->InsertFromMinibuffer(j - pos))
1511 for (i = pos_end; i >= pos; --i)
1519 // just an idea of me
1521 tmp->line_top = firstpar->line_top;
1522 tmp->pagebreak_top = firstpar->pagebreak_top;
1523 tmp->added_space_top = firstpar->added_space_top;
1524 tmp->bibkey = firstpar->bibkey;
1526 // layout stays the same with latex-environments
1528 firstpar->SetOnlyLayout(bparams, tmp->layout);
1529 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1530 firstpar->depth = tmp->depth;
1534 // just an idea of me
1536 tmp->line_top = line_top;
1537 tmp->pagebreak_top = pagebreak_top;
1538 tmp->added_space_top = added_space_top;
1539 tmp->bibkey = bibkey;
1541 // layout stays the same with latex-environments
1543 SetOnlyLayout(bparams, tmp->layout);
1544 SetLabelWidthString(tmp->labelwidthstring);
1552 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1555 par = par->FirstPhysicalPar();
1556 footnoteflag = par->footnoteflag;
1557 footnotekind = par->footnotekind;
1559 layout = par->layout;
1560 align = par-> align;
1561 SetLabelWidthString(par->labelwidthstring);
1563 line_bottom = par->line_bottom;
1564 pagebreak_bottom = par->pagebreak_bottom;
1565 added_space_bottom = par->added_space_bottom;
1567 line_top = par->line_top;
1568 pagebreak_top = par->pagebreak_top;
1569 added_space_top = par->added_space_top;
1571 spacing = par->spacing;
1573 pextra_type = par->pextra_type;
1574 pextra_width = par->pextra_width;
1575 pextra_widthp = par->pextra_widthp;
1576 pextra_alignment = par->pextra_alignment;
1577 pextra_hfill = par->pextra_hfill;
1578 pextra_start_minipage = par->pextra_start_minipage;
1580 noindent = par->noindent;
1586 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1588 LyXParagraph * tmppar = this;
1591 && tmppar->previous->footnoteflag ==
1592 LyXParagraph::CLOSED_FOOTNOTE)
1593 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1594 tmppar = tmppar->previous;
1597 return this; // This should never happen!
1604 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1606 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1621 && (IsNewline(0) || IsLineSeparator(0))){
1630 LyXParagraph * LyXParagraph::Clone() const
1632 // create a new paragraph
1633 LyXParagraph * result = new LyXParagraph;
1635 result->MakeSameLayout(this);
1637 // this is because of the dummy layout of the paragraphs that
1639 result->layout = layout;
1642 /* table stuff -- begin*/
1644 result->table = table->Clone();
1647 /* table stuff -- end*/
1649 result->inset_owner = inset_owner;
1652 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1655 // copy everything behind the break-position to the new paragraph
1657 result->text = text;
1658 result->fontlist = fontlist;
1659 result->insetlist = insetlist;
1660 for (InsetList::iterator it = result->insetlist.begin();
1661 it != result->insetlist.end(); ++it)
1662 (*it).inset = (*it).inset->Clone();
1667 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1670 par = par->FirstPhysicalPar();
1675 par->footnoteflag == footnoteflag &&
1676 par->footnotekind == footnotekind &&
1678 par->layout == layout &&
1680 par->align == align &&
1682 par->line_bottom == line_bottom &&
1683 par->pagebreak_bottom == pagebreak_bottom &&
1684 par->added_space_bottom == added_space_bottom &&
1686 par->line_top == line_top &&
1687 par->pagebreak_top == pagebreak_top &&
1688 par->added_space_top == added_space_top &&
1690 par->spacing == spacing &&
1692 par->pextra_type == pextra_type &&
1693 par->pextra_width == pextra_width &&
1694 par->pextra_widthp == pextra_widthp &&
1695 par->pextra_alignment == pextra_alignment &&
1696 par->pextra_hfill == pextra_hfill &&
1697 par->pextra_start_minipage == pextra_start_minipage &&
1699 par->table == table && // what means: NO TABLE AT ALL
1702 par->noindent == noindent &&
1703 par->depth == depth);
1707 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1708 LyXParagraph::size_type pos)
1711 // create a new paragraph
1712 LyXParagraph * par = ParFromPos(pos);
1714 LyXParagraph * tmp = new LyXParagraph(par);
1716 tmp->MakeSameLayout(par);
1718 // When can pos < Last()?
1719 // I guess pos == Last() is possible.
1721 // copy everything behind the break-position to the new
1723 size_type pos_first = 0;
1724 while (ParFromPos(pos_first) != par)
1726 size_type pos_end = pos_first + par->text.size() - 1;
1729 for (i = j = pos; i <= pos_end; ++i) {
1730 par->CutIntoMinibuffer(bparams, i - pos_first);
1731 if (tmp->InsertFromMinibuffer(j - pos))
1734 tmp->text.resize(tmp->text.size());
1735 for (size_type i = pos_end; i >= pos; --i)
1736 par->Erase(i - pos_first);
1738 par->text.resize(par->text.size());
1741 // create a new paragraph
1742 LyXParagraph * tmp = new LyXParagraph(this);
1743 tmp->MakeSameLayout(this);
1745 // When can pos > Last()?
1746 // I guess pos == Last() is possible.
1748 // copy everything behind the break-position to the new
1750 size_type pos_end = text.size() - 1;
1753 for (i = j = pos; i <= pos_end; ++i) {
1754 CutIntoMinibuffer(bparams, i);
1755 if (tmp->InsertFromMinibuffer(j - pos))
1761 for (size_type i = pos_end; i >= pos; --i)
1770 // Be carefull, this does not make any check at all.
1771 // This method has wrong name, it combined this par with the next par.
1772 // In that sense it is the reverse of break paragraph. (Lgb)
1773 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1775 // copy the next paragraph to this one
1776 LyXParagraph * the_next = Next();
1778 LyXParagraph * firstpar = FirstPhysicalPar();
1781 // first the DTP-stuff
1783 firstpar->line_bottom = the_next->line_bottom;
1784 firstpar->added_space_bottom = the_next->added_space_bottom;
1785 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1787 line_bottom = the_next->line_bottom;
1788 added_space_bottom = the_next->added_space_bottom;
1789 pagebreak_bottom = the_next->pagebreak_bottom;
1792 size_type pos_end = the_next->text.size() - 1;
1793 size_type pos_insert = Last();
1795 // ok, now copy the paragraph
1797 for (i = j = 0; i <= pos_end; ++i) {
1798 the_next->CutIntoMinibuffer(bparams, i);
1799 if (InsertFromMinibuffer(pos_insert + j))
1803 // delete the next paragraph
1804 LyXParagraph * ppar = the_next->previous;
1805 LyXParagraph * npar = the_next->next;
1812 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1814 LyXParagraph * par = ParFromPos(pos);
1816 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1817 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1823 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1825 LyXParagraph * par = ParFromPos(pos);
1827 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1828 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1835 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1837 LyXParagraph const * par = this;
1838 int par_depth = GetDepth();
1840 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1842 textclasslist.Style(bparams.textclass,
1843 layout).endlabeltype;
1844 if (endlabeltype != END_LABEL_NO_LABEL) {
1845 LyXParagraph const * last = this;
1847 if( footnoteflag == NO_FOOTNOTE)
1848 last = LastPhysicalPar();
1849 else if (next->footnoteflag == NO_FOOTNOTE)
1850 return endlabeltype;
1855 if (!last || !last->next)
1856 return endlabeltype;
1858 int next_depth = last->next->GetDepth();
1859 if (par_depth > next_depth ||
1860 (par_depth == next_depth && layout != last->next->GetLayout() ))
1861 return endlabeltype;
1866 par = par->DepthHook(par_depth - 1);
1868 par_depth = par->GetDepth();
1870 return END_LABEL_NO_LABEL;
1874 LyXTextClass::size_type LyXParagraph::GetLayout() const
1877 return FirstPhysicalPar()->layout;
1884 char LyXParagraph::GetDepth() const
1887 return FirstPhysicalPar()->depth;
1894 char LyXParagraph::GetAlign() const
1897 return FirstPhysicalPar()->align;
1904 string const & LyXParagraph::GetLabelstring() const
1907 return FirstPhysicalPar()->labelstring;
1914 int LyXParagraph::GetFirstCounter(int i) const
1917 return FirstPhysicalPar()->counter_[i];
1924 // the next two functions are for the manual labels
1925 string LyXParagraph::GetLabelWidthString() const
1928 if (!FirstPhysicalPar()->labelwidthstring.empty())
1929 return FirstPhysicalPar()->labelwidthstring;
1931 if (!labelwidthstring.empty())
1932 return labelwidthstring;
1935 return _("Senseless with this layout!");
1939 void LyXParagraph::SetLabelWidthString(string const & s)
1942 LyXParagraph * par = FirstPhysicalPar();
1944 par->labelwidthstring = s;
1946 labelwidthstring = s;
1951 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1952 LyXTextClass::size_type new_layout)
1955 LyXParagraph * par = FirstPhysicalPar();
1957 LyXParagraph * par = this;
1959 LyXParagraph * ppar = 0;
1960 LyXParagraph * npar = 0;
1962 par->layout = new_layout;
1964 /* table stuff -- begin*/
1967 /* table stuff -- end*/
1969 if (par->pextra_type == PEXTRA_NONE) {
1970 if (par->Previous()) {
1972 ppar = par->Previous()->FirstPhysicalPar();
1974 ppar = par->Previous();
1978 && (ppar->depth > par->depth))
1980 ppar = ppar->Previous()->FirstPhysicalPar();
1982 ppar = ppar->Previous();
1987 npar = par->Next()->NextAfterFootnote();
1993 && (npar->depth > par->depth))
1995 npar = npar->Next()->NextAfterFootnote();
1997 npar = npar->Next();
2000 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2002 p1 = ppar->pextra_width,
2003 p2 = ppar->pextra_widthp;
2004 ppar->SetPExtraType(bparams, ppar->pextra_type,
2005 p1.c_str(), p2.c_str());
2007 if ((par->pextra_type == PEXTRA_NONE) &&
2008 npar && (npar->pextra_type != PEXTRA_NONE)) {
2010 p1 = npar->pextra_width,
2011 p2 = npar->pextra_widthp;
2012 npar->SetPExtraType(bparams, npar->pextra_type,
2013 p1.c_str(), p2.c_str());
2019 void LyXParagraph::SetLayout(BufferParams const & bparams,
2020 LyXTextClass::size_type new_layout)
2024 * par = FirstPhysicalPar(),
2031 par->layout = new_layout;
2032 par->labelwidthstring.erase();
2033 par->align = LYX_ALIGN_LAYOUT;
2034 par->added_space_top = VSpace(VSpace::NONE);
2035 par->added_space_bottom = VSpace(VSpace::NONE);
2036 par->spacing.set(Spacing::Default);
2039 /* table stuff -- begin*/
2042 /* table stuff -- end*/
2044 if (par->pextra_type == PEXTRA_NONE) {
2045 if (par->Previous()) {
2047 ppar = par->Previous()->FirstPhysicalPar();
2049 ppar = par->Previous();
2053 && (ppar->depth > par->depth))
2055 ppar = ppar->Previous()->FirstPhysicalPar();
2057 ppar = ppar->Previous();
2062 npar = par->Next()->NextAfterFootnote();
2068 && (npar->depth > par->depth))
2070 npar = npar->Next()->NextAfterFootnote();
2072 npar = npar->Next();
2075 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2077 p1 = ppar->pextra_width,
2078 p2 = ppar->pextra_widthp;
2079 ppar->SetPExtraType(bparams, ppar->pextra_type,
2080 p1.c_str(), p2.c_str());
2082 if ((par->pextra_type == PEXTRA_NONE) &&
2083 npar && (npar->pextra_type != PEXTRA_NONE)) {
2085 p1 = npar->pextra_width,
2086 p2 = npar->pextra_widthp;
2087 npar->SetPExtraType(bparams, npar->pextra_type,
2088 p1.c_str(), p2.c_str());
2094 // if the layout of a paragraph contains a manual label, the beginning of the
2095 // main body is the beginning of the second word. This is what the par-
2096 // function returns. If the layout does not contain a label, the main
2097 // body always starts with position 0. This differentiation is necessary,
2098 // because there cannot be a newline or a blank <= the beginning of the
2099 // main body in TeX.
2101 int LyXParagraph::BeginningOfMainBody() const
2104 if (FirstPhysicalPar() != this)
2107 // Unroll the first two cycles of the loop
2108 // and remember the previous character to
2109 // remove unnecessary GetChar() calls
2112 && GetChar(i) != LyXParagraph::META_NEWLINE
2115 char previous_char = 0, temp = 0;
2117 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2118 // Yes, this ^ is supposed to be "= " not "=="
2121 && previous_char != ' '
2122 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2124 previous_char = temp;
2130 if (i == 0 && i == size() &&
2131 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2132 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2133 ++i; /* the cursor should not jump
2134 * to the main body if there
2141 LyXParagraph * LyXParagraph::DepthHook(int deth)
2143 LyXParagraph * newpar = this;
2149 newpar = newpar->FirstPhysicalPar()->Previous();
2151 newpar = newpar->Previous();
2153 } while (newpar && newpar->GetDepth() > deth
2155 && newpar->footnoteflag == footnoteflag
2160 if (Previous() || GetDepth())
2161 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2166 return newpar->FirstPhysicalPar();
2173 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2175 LyXParagraph const * newpar = this;
2181 newpar = newpar->FirstPhysicalPar()->Previous();
2183 newpar = newpar->Previous();
2185 } while (newpar && newpar->GetDepth() > deth
2187 && newpar->footnoteflag == footnoteflag
2192 if (Previous() || GetDepth())
2193 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2198 return newpar->FirstPhysicalPar();
2205 int LyXParagraph::AutoDeleteInsets()
2208 InsetList::size_type index = 0;
2209 while (index < insetlist.size()) {
2210 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2211 Erase(insetlist[index].pos);
2212 // Erase() calls to insetlist.erase(&insetlist[index])
2213 // so index shouldn't be increased.
2222 LyXParagraph::inset_iterator
2223 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2225 InsetTable search_inset(pos, 0);
2226 InsetList::iterator it = lower_bound(insetlist.begin(),
2228 search_inset, matchIT());
2229 return inset_iterator(it);
2233 // returns -1 if inset not found
2234 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2237 for (InsetList::const_iterator cit = insetlist.begin();
2238 cit != insetlist.end(); ++cit) {
2239 if ((*cit).inset == inset) {
2244 // Think about footnotes.
2245 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2246 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2248 NextAfterFootnote()->GetPositionOfInset(inset);
2250 return text.size() + 1 + further;
2257 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2258 BufferParams const & bparams,
2259 ostream & os, TexRow & texrow,
2264 TexRow & foot_texrow,
2269 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2270 LyXLayout const & style =
2271 textclasslist.Style(bparams.textclass,
2274 bool further_blank_line = false;
2277 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2280 if (start_of_appendix) {
2281 os << "\\appendix\n";
2285 if (!spacing.isDefault()
2286 && (!Previous() || !Previous()->HasSameLayout(this))) {
2287 os << spacing.writeEnvirBegin() << "\n";
2291 if (tex_code_break_column && style.isCommand()){
2296 if (pagebreak_top) {
2298 further_blank_line = true;
2300 if (added_space_top.kind() != VSpace::NONE) {
2301 os << added_space_top.asLatexCommand(bparams);
2302 further_blank_line = true;
2306 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2307 << "\\vspace{-1\\parskip}";
2308 further_blank_line = true;
2311 if (further_blank_line){
2316 Language const * language = getParLanguage(bparams);
2317 Language const * doc_language = bparams.language_info;
2318 Language const * previous_language = previous
2319 ? previous->getParLanguage(bparams) : doc_language;
2320 if (language != doc_language && language != previous_language) {
2321 os << subst(lyxrc.language_command_begin, "$$lang",
2327 if (bparams.inputenc == "auto" &&
2328 language->encoding() != previous_language->encoding()) {
2329 os << "\\inputencoding{"
2330 << language->encoding()->LatexName()
2335 switch (style.latextype) {
2338 << style.latexname()
2339 << style.latexparam();
2341 case LATEX_ITEM_ENVIRONMENT:
2343 bibkey->Latex(buf, os, false, false);
2347 case LATEX_LIST_ENVIRONMENT:
2354 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2356 LyXParagraph * par = next;
2358 // Spit out footnotes
2359 if (lyxrc.rtl_support) {
2360 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2361 && next->footnoteflag != footnoteflag) {
2362 LyXParagraph * p = 0;
2363 bool is_rtl = (size() > 0)
2364 ? GetFontSettings(bparams,
2365 size()-1).isRightToLeft()
2366 : language->RightToLeft();
2367 if ( (p = NextAfterFootnote()) != 0 &&
2369 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2370 is_rtl = getParLanguage(bparams)->RightToLeft();
2371 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2372 && par->footnoteflag != footnoteflag) {
2373 par = par->TeXFootnote(buf, bparams,
2375 foot_texrow, foot_count,
2377 par->SimpleTeXOnePar(buf, bparams,
2378 os, texrow, moving_arg);
2379 is_rtl = (par->size() > 0)
2380 ? par->GetFontSettings(bparams,
2381 par->size()-1).isRightToLeft()
2382 : language->RightToLeft();
2384 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2385 (p = par->NextAfterFootnote()) != 0 &&
2387 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2388 is_rtl = language->RightToLeft();
2393 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2394 && par->footnoteflag != footnoteflag) {
2395 par = par->TeXFootnote(buf, bparams,
2397 foot, foot_texrow, foot_count,
2399 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2405 // Make sure that \\par is done with the font of the last
2406 // character if this has another size as the default.
2407 // This is necessary because LaTeX (and LyX on the screen)
2408 // calculates the space between the baselines according
2409 // to this font. (Matthias)
2410 LyXFont font = getFont(bparams, Last() - 1);
2412 if (style.resfont.size() != font.size()) {
2418 } else if (textclasslist.Style(bparams.textclass,
2419 GetLayout()).isCommand()) {
2420 if (style.resfont.size() != font.size()) {
2426 } else if (style.resfont.size() != font.size()){
2427 os << "{\\" << font.latexSize() << " \\par}";
2430 if (language != doc_language &&
2433 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2435 || par->getParLanguage(bparams) != language)) {
2437 << subst(lyxrc.language_command_end, "$$lang",
2438 doc_language->lang());
2441 switch (style.latextype) {
2442 case LATEX_ITEM_ENVIRONMENT:
2443 case LATEX_LIST_ENVIRONMENT:
2444 if (par && (depth < par->depth)) {
2449 case LATEX_ENVIRONMENT:
2450 // if its the last paragraph of the current environment
2451 // skip it otherwise fall through
2453 && (par->layout != layout
2454 || par->depth != depth
2455 || par->pextra_type != pextra_type))
2458 // we don't need it for the last paragraph!!!
2461 && !( footnoteflag != LyXParagraph::NO_FOOTNOTE
2462 && footnotekind != LyXParagraph::FOOTNOTE
2463 && footnotekind != LyXParagraph::MARGIN)
2471 // don't insert this if we would be adding it
2472 // before or after a table in a float. This
2473 // little trick is needed in order to allow
2474 // use of tables in \subfigures or \subtables.
2480 further_blank_line = false;
2482 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2483 further_blank_line = true;
2486 if (added_space_bottom.kind() != VSpace::NONE) {
2487 os << added_space_bottom.asLatexCommand(bparams);
2488 further_blank_line = true;
2491 if (pagebreak_bottom) {
2493 further_blank_line = true;
2496 if (further_blank_line){
2501 if (!spacing.isDefault()
2502 && (!par || !par->HasSameLayout(this))) {
2503 os << spacing.writeEnvirEnd() << "\n";
2507 // we don't need it for the last paragraph!!!
2510 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2511 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2518 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2523 // This one spits out the text of the paragraph
2524 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2525 BufferParams const & bparams,
2526 ostream & os, TexRow & texrow,
2529 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2533 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2536 bool return_value = false;
2538 LyXLayout const & style =
2539 textclasslist.Style(bparams.textclass,
2541 LyXFont basefont, last_font;
2543 // Maybe we have to create a optional argument.
2544 size_type main_body;
2545 if (style.labeltype != LABEL_MANUAL)
2548 main_body = BeginningOfMainBody();
2550 if (main_body > 0) {
2552 basefont = getFont(bparams, -2); // Get label font
2554 basefont = getFont(bparams, -1); // Get layout font
2565 if (style.isCommand()) {
2568 } else if (align != LYX_ALIGN_LAYOUT) {
2571 return_value = true;
2575 moving_arg |= style.needprotect;
2577 // Which font is currently active?
2578 LyXFont running_font(basefont);
2579 // Do we have an open font change?
2580 bool open_font = false;
2582 texrow.start(this, 0);
2584 for (size_type i = 0; i < size(); ++i) {
2586 // First char in paragraph or after label?
2592 if (main_body > 0) {
2594 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2597 basefont = getFont(bparams, -1); // Now use the layout font
2598 running_font = basefont;
2602 if (style.isCommand()) {
2605 } else if (align != LYX_ALIGN_LAYOUT) {
2608 return_value = true;
2612 os << "\\noindent ";
2616 case LYX_ALIGN_NONE:
2617 case LYX_ALIGN_BLOCK:
2618 case LYX_ALIGN_LAYOUT:
2619 case LYX_ALIGN_SPECIAL:
2621 case LYX_ALIGN_LEFT:
2622 if (getParLanguage(bparams)->lang() != "hebrew") {
2623 os << "\\raggedright ";
2626 os << "\\raggedleft ";
2630 case LYX_ALIGN_RIGHT:
2631 if (getParLanguage(bparams)->lang() != "hebrew") {
2632 os << "\\raggedleft ";
2635 os << "\\raggedright ";
2639 case LYX_ALIGN_CENTER:
2640 os << "\\centering ";
2646 value_type c = GetChar(i);
2648 // Fully instantiated font
2649 LyXFont font = getFont(bparams, i);
2651 LyXParagraph * p = 0;
2654 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2655 (p = PreviousBeforeFootnote()) != 0)
2656 last_font = p->getFont(bparams, p->size() - 1);
2659 last_font = running_font;
2661 // Spaces at end of font change are simulated to be
2662 // outside font change, i.e. we write "\textXX{text} "
2663 // rather than "\textXX{text }". (Asger)
2664 if (open_font && c == ' ' && i <= size() - 2
2665 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2666 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2667 font = getFont(bparams, i + 1);
2669 // We end font definition before blanks
2670 if (!font.equalExceptLatex(running_font) && open_font) {
2671 column += running_font.latexWriteEndChanges(os,
2673 (i == main_body-1) ? basefont : font);
2674 running_font = basefont;
2678 // Blanks are printed before start of fontswitch
2680 // Do not print the separation of the optional argument
2681 if (i != main_body - 1) {
2682 SimpleTeXBlanks(os, texrow, i,
2683 column, font, style);
2687 // Do we need to change font?
2688 if (!font.equalExceptLatex(running_font)
2689 && i != main_body-1) {
2690 column += font.latexWriteStartChanges(os, basefont,
2692 running_font = font;
2696 if (c == LyXParagraph::META_NEWLINE) {
2697 // newlines are handled differently here than
2698 // the default in SimpleTeXSpecialChars().
2699 if (!style.newline_allowed
2700 || font.latex() == LyXFont::ON) {
2704 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2707 basefont = getFont(bparams, -1);
2708 running_font = basefont;
2709 if (font.family() ==
2710 LyXFont::TYPEWRITER_FAMILY) {
2718 texrow.start(this, i + 1);
2721 SimpleTeXSpecialChars(buf, bparams,
2722 os, texrow, moving_arg,
2723 font, running_font, basefont,
2724 open_font, style, i, column, c);
2728 // If we have an open font definition, we have to close it
2730 LyXParagraph * p = 0;
2733 && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2734 && (p = NextAfterFootnote()) != 0
2739 running_font.latexWriteEndChanges(os, basefont,
2740 p->getFont(bparams, 0));
2742 running_font.latexWriteEndChanges(os, basefont, basefont);
2745 // Needed if there is an optional argument but no contents.
2746 if (main_body > 0 && main_body == size()) {
2748 return_value = false;
2751 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2752 return return_value;
2757 // This one spits out the text of a table paragraph
2758 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2759 BufferParams const & bparams,
2760 ostream & os, TexRow & texrow)
2762 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2764 bool return_value = false;
2766 LyXLayout const & style =
2767 textclasslist.Style(bparams.textclass, GetLayout());
2771 if (!IsDummy()) { // it is dummy if it is in a float!!!
2773 if (style.isCommand()) {
2776 } else if (align != LYX_ALIGN_LAYOUT) {
2779 return_value = true;
2782 os << "\\noindent ";
2786 case LYX_ALIGN_NONE:
2787 case LYX_ALIGN_BLOCK:
2788 case LYX_ALIGN_LAYOUT:
2789 case LYX_ALIGN_SPECIAL: break;
2790 case LYX_ALIGN_LEFT:
2791 os << "\\raggedright ";
2794 case LYX_ALIGN_RIGHT:
2795 os << "\\raggedleft ";
2798 case LYX_ALIGN_CENTER:
2799 os << "\\centering ";
2807 LyXFont basefont = getFont(bparams, -1); // Get layout font
2808 // Which font is currently active?
2809 LyXFont running_font = basefont;
2811 // Do we have an open font change?
2812 bool open_font = false;
2813 int current_cell_number = -1;
2814 int tmp = table->TexEndOfCell(os, current_cell_number);
2815 for (; tmp > 0 ; --tmp)
2818 texrow.start(this, 0);
2820 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2821 bool first_in_cell = true;
2823 for (size_type i = 0; i < size(); ++i) {
2824 value_type c = GetChar(i);
2825 if (table->IsContRow(current_cell_number + 1)) {
2826 if (c == LyXParagraph::META_NEWLINE)
2827 ++current_cell_number;
2832 if (first_in_cell && is_rtl) {
2835 first_in_cell = false;
2838 // Fully instantiated font
2839 LyXFont font = getFont(bparams, i);
2840 last_font = running_font;
2842 // Spaces at end of font change are simulated to be
2843 // outside font change.
2844 // i.e. we write "\textXX{text} " rather than
2845 // "\textXX{text }". (Asger)
2846 if (open_font && c == ' ' && i <= size() - 2
2847 && getFont(bparams, i + 1) != running_font
2848 && getFont(bparams, i + 1) != font) {
2849 font = getFont(bparams, i + 1);
2852 // We end font definition before blanks
2853 if (font != running_font && open_font) {
2854 column += running_font.latexWriteEndChanges(os,
2857 running_font = basefont;
2860 // Blanks are printed before start of fontswitch
2862 SimpleTeXBlanks(os, texrow, i, column, font, style);
2864 // Do we need to change font?
2865 if (font != running_font) {
2866 column += font.latexWriteStartChanges(os, basefont,
2868 running_font = font;
2871 // Do we need to turn on LaTeX mode?
2872 if (font.latex() != running_font.latex()) {
2873 if (font.latex() == LyXFont::ON
2874 && style.needprotect) {
2879 if (c == LyXParagraph::META_NEWLINE) {
2880 // special case for inside a table
2881 // different from default case in
2882 // SimpleTeXSpecialChars()
2884 column += running_font
2885 .latexWriteEndChanges(os, basefont,
2889 basefont = getFont(bparams, -1);
2890 running_font = basefont;
2891 ++current_cell_number;
2892 if (table->CellHasContRow(current_cell_number) >= 0) {
2893 TeXContTableRows(buf, bparams, os, i + 1,
2894 current_cell_number,
2897 if (is_rtl && !first_in_cell) {
2899 first_in_cell = true;
2902 // if this cell follow only ContRows till end don't
2903 // put the EndOfCell because it is put after the
2905 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2906 --current_cell_number;
2909 int tmp = table->TexEndOfCell(os,
2910 current_cell_number);
2913 } else if (tmp < 0) {
2919 texrow.start(this, i + 1);
2921 SimpleTeXSpecialChars(buf, bparams,
2923 font, running_font, basefont,
2924 open_font, style, i, column, c);
2928 // If we have an open font definition, we have to close it
2930 running_font.latexWriteEndChanges(os, basefont, basefont);
2932 ++current_cell_number;
2933 if (is_rtl && !first_in_cell)
2935 tmp = table->TexEndOfCell(os, current_cell_number);
2936 for (; tmp > 0; --tmp)
2938 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2939 return return_value;
2945 // This one spits out the text off ContRows in tables
2946 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2947 BufferParams const & bparams,
2949 LyXParagraph::size_type i,
2950 int current_cell_number,
2951 int & column, TexRow & texrow)
2953 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2957 bool return_value = false;
2958 LyXLayout const & style =
2959 textclasslist.Style(bparams.textclass,
2961 LyXFont basefont = getFont(bparams, -1); // Get layout font
2963 // Which font is currently active?
2964 LyXFont running_font = basefont;
2965 // Do we have an open font change?
2966 bool open_font = false;
2968 size_type lastpos = i;
2969 int cell = table->CellHasContRow(current_cell_number);
2970 ++current_cell_number;
2973 // first find the right position
2975 for (; (i < size()) && (current_cell_number < cell); ++i) {
2977 if (c == LyXParagraph::META_NEWLINE)
2978 ++current_cell_number;
2982 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2986 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2991 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2995 // Fully instantiated font
2996 LyXFont font = getFont(bparams, i);
2997 last_font = running_font;
2999 // Spaces at end of font change are simulated to
3000 // be outside font change. i.e. we write
3001 // "\textXX{text} " rather than "\textXX{text }".
3003 if (open_font && c == ' ' && i <= size() - 2
3004 && getFont(bparams, i + 1) != running_font
3005 && getFont(bparams, i + 1) != font) {
3006 font = getFont(bparams, i + 1);
3009 // We end font definition before blanks
3010 if (font != running_font && open_font) {
3011 column += running_font.latexWriteEndChanges(os, basefont, font);
3012 running_font = basefont;
3015 // Blanks are printed before start of fontswitch
3017 SimpleTeXBlanks(os, texrow, i,
3018 column, font, style);
3020 // Do we need to change font?
3021 if (font != running_font) {
3023 font.latexWriteStartChanges(os,
3026 running_font = font;
3029 // Do we need to turn on LaTeX mode?
3030 if (font.latex() != running_font.latex()) {
3031 if (font.latex() == LyXFont::ON
3032 && style.needprotect) {
3037 SimpleTeXSpecialChars(buf, bparams,
3038 os, texrow, false, font,
3039 running_font, basefont,
3040 open_font, style, i, column, c);
3042 // If we have an open font definition, we have to close it
3044 running_font.latexWriteEndChanges(os, basefont,
3048 basefont = getFont(bparams, -1);
3049 running_font = basefont;
3050 cell = table->CellHasContRow(current_cell_number);
3052 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
3053 return return_value;
3058 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
3060 bool retval = false;
3062 case LyXParagraph::META_HFILL:
3063 sgml_string.erase();
3065 case LyXParagraph::META_NEWLINE:
3069 sgml_string = "&";
3072 sgml_string = "<";
3075 sgml_string = ">";
3078 sgml_string = "$";
3081 sgml_string = "#";
3084 sgml_string = "%";
3087 sgml_string = "[";
3090 sgml_string = "]";
3093 sgml_string = "{";
3096 sgml_string = "}";
3099 sgml_string = "˜";
3102 sgml_string = """;
3105 sgml_string = "\";
3111 case '\0': // Ignore :-)
3112 sgml_string.erase();
3123 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
3124 ostream & os, string & extra,
3125 int & desc_on, int depth)
3127 BufferParams const & bparams = buffer->params;
3129 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
3131 LyXFont font1, font2;
3134 size_type main_body;
3135 bool emph_flag = false;
3137 LyXLayout const & style =
3138 textclasslist.Style(bparams.textclass,
3141 if (style.labeltype != LABEL_MANUAL)
3144 main_body = BeginningOfMainBody();
3146 // Gets paragraph main font.
3148 font1 = style.labelfont;
3152 int char_line_count = depth;
3153 os << newlineAndDepth(depth);
3155 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3156 os << "<INFORMALTABLE>"
3157 << newlineAndDepth(++depth);
3160 os << "<INFORMALTABLE>"
3161 << newlineAndDepth(++depth);
3163 int current_cell_number = -1;
3164 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3166 // Parsing main loop.
3167 for (size_type i = 0; i < size(); ++i) {
3169 if (table->IsContRow(current_cell_number+1)) {
3170 if (c == LyXParagraph::META_NEWLINE)
3171 ++current_cell_number;
3176 // Fully instantiated font
3177 font2 = getFont(bparams, i);
3179 // Handle <emphasis> tag.
3180 if (font1.emph() != font2.emph() && i) {
3181 if (font2.emph() == LyXFont::ON) {
3184 } else if (emph_flag) {
3185 os << "</emphasis>";
3189 if (c == LyXParagraph::META_NEWLINE) {
3190 // We have only to control for emphasis open here!
3192 os << "</emphasis>";
3195 font1 = font2 = getFont(bparams, -1);
3196 ++current_cell_number;
3197 if (table->CellHasContRow(current_cell_number) >= 0) {
3198 DocBookContTableRows(buffer,
3199 os, extra, desc_on, i + 1,
3200 current_cell_number,
3203 // if this cell follow only ContRows till end don't
3204 // put the EndOfCell because it is put after the
3206 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3207 --current_cell_number;
3210 tmp = table->DocBookEndOfCell(os,
3211 current_cell_number,
3216 } else if (c == LyXParagraph::META_INSET) {
3217 inset = GetInset(i);
3219 std::ostringstream ost;
3220 inset->DocBook(buffer, ost);
3221 string tmp_out = ost.str().c_str();
3224 inset->DocBook(buffer, ost);
3226 char * ctmp = ost.str();
3227 string tmp_out(ctmp);
3231 // This code needs some explanation:
3232 // Two insets are treated specially
3233 // label if it is the first element in a
3234 // command paragraph
3236 // graphics inside tables or figure floats
3238 // title (the equivalente in latex for this
3240 // and title should come first
3243 if(desc_on != 3 || i != 0) {
3244 if(tmp_out[0] == '@') {
3246 extra += frontStrip(tmp_out,
3249 os << frontStrip(tmp_out,
3254 } else if (font2.latex() == LyXFont::ON) {
3255 // "TeX"-Mode on == > SGML-Mode on.
3261 if (linuxDocConvertChar(c, sgml_string)
3262 && !style.free_spacing) {
3263 // in freespacing mode, spaces are
3264 // non-breaking characters
3269 << "</term><listitem><para>";
3281 // Needed if there is an optional argument but no contents.
3282 if (main_body > 0 && main_body == size()) {
3287 os << "</emphasis>";
3290 ++current_cell_number;
3291 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3292 // Resets description flag correctly.
3295 // <term> not closed...
3300 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3302 os << "</INFORMALTABLE>";
3304 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3311 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3312 ostream & os, string & extra,
3314 LyXParagraph::size_type i,
3315 int current_cell_number, int &column)
3320 BufferParams const & bparams = buffer->params;
3322 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3327 //string emph = "emphasis";
3328 bool emph_flag = false;
3329 int char_line_count = 0;
3331 LyXLayout const & style =
3332 textclasslist.Style(bparams.textclass,
3335 size_type main_body;
3336 if (style.labeltype != LABEL_MANUAL)
3339 main_body = BeginningOfMainBody();
3341 // Gets paragraph main font.
3344 font1 = style.labelfont;
3348 size_type lastpos = i;
3349 int cell = table->CellHasContRow(current_cell_number);
3350 ++current_cell_number;
3352 // first find the right position
3354 for (; i < size() && current_cell_number < cell; ++i) {
3356 if (c == LyXParagraph::META_NEWLINE)
3357 ++current_cell_number;
3361 // I don't know how to handle this so I comment it
3362 // for the moment (Jug)
3363 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3364 // file += " \\\\\n";
3367 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3372 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3376 // Fully instantiated font
3377 font2 = getFont(bparams, i);
3379 // Handle <emphasis> tag.
3380 if (font1.emph() != font2.emph() && i) {
3381 if (font2.emph() == LyXFont::ON) {
3384 } else if (emph_flag) {
3385 os << "</emphasis>";
3389 if (c == LyXParagraph::META_INSET) {
3390 inset = GetInset(i);
3392 std::ostringstream ost;
3393 inset->DocBook(buffer, ost);
3394 string tmp_out = ost.str().c_str();
3397 inset->DocBook(buffer, ost);
3399 char * ctmp = ost.str();
3400 string tmp_out(ctmp);
3404 // This code needs some explanation:
3405 // Two insets are treated specially
3406 // label if it is the first element in a
3407 // command paragraph
3409 // graphics inside tables or figure floats
3410 // can't go on title (the equivalente in
3411 // latex for this case is caption and title
3412 // should come first
3415 if(desc_on != 3 || i != 0) {
3416 if(tmp_out[0] == '@') {
3418 extra += frontStrip(tmp_out, '@');
3420 os << frontStrip(tmp_out, '@');
3424 } else if (font2.latex() == LyXFont::ON) {
3425 // "TeX"-Mode on == > SGML-Mode on.
3431 if (linuxDocConvertChar(c, sgml_string)
3432 && !style.free_spacing) {
3433 // in freespacing mode, spaces are
3434 // non-breaking characters
3439 << "</term><listitem><para>";
3449 // we have only to control for emphasis open here!
3451 os << "</emphasis>";
3454 font1 = font2 = getFont(bparams, -1);
3455 cell = table->CellHasContRow(current_cell_number);
3457 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3462 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3463 LyXParagraph::size_type const i,
3464 int & column, LyXFont const & font,
3465 LyXLayout const & style)
3467 if (column > tex_code_break_column
3469 && GetChar(i - 1) != ' '
3471 // In LaTeX mode, we don't want to
3472 // break lines since some commands
3474 && ! (font.latex() == LyXFont::ON)
3475 // same in FreeSpacing mode
3476 && !style.free_spacing
3477 // In typewriter mode, we want to avoid
3478 // ! . ? : at the end of a line
3479 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3480 && (GetChar(i-1) == '.'
3481 || GetChar(i-1) == '?'
3482 || GetChar(i-1) == ':'
3483 || GetChar(i-1) == '!'))) {
3484 if (tex_code_break_column == 0) {
3485 // in batchmode we need LaTeX to still
3486 // see it as a space not as an extra '\n'
3492 texrow.start(this, i + 1);
3494 } else if (font.latex() == LyXFont::OFF) {
3495 if (style.free_spacing) {
3504 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3505 BufferParams const & bparams,
3506 ostream & os, TexRow & texrow,
3509 LyXFont & running_font,
3512 LyXLayout const & style,
3513 LyXParagraph::size_type & i,
3515 LyXParagraph::value_type const c)
3517 // Two major modes: LaTeX or plain
3518 // Handle here those cases common to both modes
3519 // and then split to handle the two modes separately.
3521 case LyXParagraph::META_INSET: {
3522 Inset * inset = GetInset(i);
3525 int len = os.tellp();
3526 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3527 || inset->LyxCode() == Inset::MATH_CODE
3528 || inset->LyxCode() == Inset::URL_CODE)
3529 && running_font.isRightToLeft()) {
3534 int tmp = inset->Latex(buf, os, moving_arg,
3535 style.free_spacing);
3543 column += os.tellp() - len;
3552 case LyXParagraph::META_NEWLINE:
3554 column += running_font.latexWriteEndChanges(os,
3559 basefont = getFont(bparams, -1);
3560 running_font = basefont;
3563 case LyXParagraph::META_HFILL:
3569 // And now for the special cases within each mode
3570 // Are we in LaTeX mode?
3571 if (font.latex() == LyXFont::ON) {
3572 // at present we only have one option
3573 // but I'll leave it as a switch statement
3574 // so its simpler to extend. (ARRae)
3577 // make sure that we will not print
3578 // error generating chars to the tex
3579 // file. This test would not be needed
3580 // if it were done in the buffer
3588 // Plain mode (i.e. not LaTeX)
3591 os << "\\textbackslash{}";
3595 case '°': case '±': case '²': case '³':
3596 case '×': case '÷': case '¹': case 'ª':
3597 case 'º': case '¬': case 'µ':
3598 if (bparams.inputenc == "latin1" ||
3599 (bparams.inputenc == "auto" &&
3600 font.language()->encoding()->LatexName()
3602 os << "\\ensuremath{"
3611 case '|': case '<': case '>':
3612 // In T1 encoding, these characters exist
3613 if (lyxrc.fontenc == "T1") {
3615 //... but we should avoid ligatures
3616 if ((c == '>' || c == '<')
3618 && GetChar(i + 1) == c) {
3619 //os << "\\textcompwordmark{}";
3620 // Jean-Marc, have a look at
3621 // this. IÂ think this works
3629 // Typewriter font also has them
3630 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3634 // Otherwise, we use what LaTeX
3638 os << "\\textless{}";
3642 os << "\\textgreater{}";
3646 os << "\\textbar{}";
3652 case '-': // "--" in Typewriter mode -> "-{}-"
3654 && GetChar(i + 1) == '-'
3655 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3664 os << "\\char`\\\"{}";
3669 if (bparams.inputenc == "default") {
3678 case '%': case '#': case '{':
3685 os << "\\textasciitilde{}";
3690 os << "\\textasciicircum{}";
3694 case '*': case '[': case ']':
3695 // avoid being mistaken for optional arguments
3696 os << '{' << c << '}';
3701 // Blanks are printed before font switching.
3702 // Sure? I am not! (try nice-latex)
3703 // I am sure it's correct. LyX might be smarter
3704 // in the future, but for now, nothing wrong is
3709 /* idea for labels --- begin*/
3713 && font.family() != LyXFont::TYPEWRITER_FAMILY
3714 && GetChar(i + 1) == 'y'
3715 && GetChar(i + 2) == 'X') {
3723 && font.family() != LyXFont::TYPEWRITER_FAMILY
3724 && GetChar(i + 1) == 'e'
3725 && GetChar(i + 2) == 'X') {
3730 // Check for "LaTeX2e"
3733 && font.family() != LyXFont::TYPEWRITER_FAMILY
3734 && GetChar(i + 1) == 'a'
3735 && GetChar(i + 2) == 'T'
3736 && GetChar(i + 3) == 'e'
3737 && GetChar(i + 4) == 'X'
3738 && GetChar(i + 5) == '2'
3739 && GetChar(i + 6) == 'e') {
3744 // Check for "LaTeX"
3747 && font.family() != LyXFont::TYPEWRITER_FAMILY
3748 && GetChar(i + 1) == 'a'
3749 && GetChar(i + 2) == 'T'
3750 && GetChar(i + 3) == 'e'
3751 && GetChar(i + 4) == 'X') {
3755 /* idea for labels --- end*/
3756 } else if (c != '\0') {
3766 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3767 BufferParams const & bparams,
3768 ostream & os, TexRow & texrow
3771 TexRow & foot_texrow,
3776 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3777 LyXParagraph * par = this;
3780 (par->depth == depth)
3782 && (par->footnoteflag == footnoteflag)
3787 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3789 if (textclasslist.Style(bparams.textclass,
3790 par->layout).isEnvironment()
3791 || par->pextra_type != PEXTRA_NONE) {
3792 par = par->TeXEnvironment(buf, bparams,
3800 par = par->TeXOnePar(buf, bparams,
3810 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3816 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3817 BufferParams const & bparams,
3818 ostream & os, TexRow & texrow
3821 TexRow & foot_texrow,
3826 bool eindent_open = false;
3828 bool foot_this_level = false;
3830 // flags when footnotetext should be appended to file.
3831 static bool minipage_open = false;
3832 static int minipage_open_depth = 0;
3833 char par_sep = bparams.paragraph_separation;
3835 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3838 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3841 LyXLayout const & style =
3842 textclasslist.Style(bparams.textclass,
3845 if (pextra_type == PEXTRA_INDENT) {
3846 if (!pextra_width.empty()) {
3847 os << "\\begin{LyXParagraphIndent}{"
3848 << pextra_width << "}\n";
3850 //float ib = atof(pextra_widthp.c_str())/100;
3851 // string can't handle floats at present (971109)
3852 // so I'll do a conversion by hand knowing that
3853 // the limits are 0.0 to 1.0. ARRae.
3854 os << "\\begin{LyXParagraphIndent}{";
3855 switch (pextra_widthp.length()) {
3867 os << "\\columnwidth}\n";
3870 eindent_open = true;
3872 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3873 if (pextra_hfill && Previous() &&
3874 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3875 os << "\\hfill{}\n";
3878 if (par_sep == BufferParams::PARSEP_INDENT) {
3879 os << "{\\setlength\\parindent{0pt}\n";
3882 os << "\\begin{minipage}";
3883 switch(pextra_alignment) {
3884 case MINIPAGE_ALIGN_TOP:
3887 case MINIPAGE_ALIGN_MIDDLE:
3890 case MINIPAGE_ALIGN_BOTTOM:
3894 if (!pextra_width.empty()) {
3895 os << '{' << pextra_width << "}\n";
3897 //float ib = atof(par->pextra_width.c_str())/100;
3898 // string can't handle floats at present
3899 // so I'll do a conversion by hand knowing that
3900 // the limits are 0.0 to 1.0. ARRae.
3902 switch (pextra_widthp.length()) {
3914 os << "\\columnwidth}\n";
3917 if (par_sep == BufferParams::PARSEP_INDENT) {
3918 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3921 minipage_open = true;
3922 minipage_open_depth = depth;
3925 #ifdef WITH_WARNINGS
3926 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3927 //I disabled it because it breaks when lists span on several
3930 if (style.isEnvironment()){
3931 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3932 #ifdef FANCY_FOOTNOTE_CODE
3933 if (foot_count < 0) {
3934 // flag that footnote[mark][text] should be
3935 // used for any footnotes from now on
3937 foot_this_level = true;
3940 os << "\\begin{" << style.latexname() << "}{"
3941 << labelwidthstring << "}\n";
3942 } else if (style.labeltype == LABEL_BIBLIO) {
3944 os << "\\begin{" << style.latexname() << "}{"
3945 << bibitemWidest(current_view)
3947 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3948 #ifdef FANCY_FOOTNOTE_CODE
3949 if (foot_count < 0) {
3950 // flag that footnote[mark][text] should be
3951 // used for any footnotes from now on
3953 foot_this_level = true;
3956 os << "\\begin{" << style.latexname() << '}'
3957 << style.latexparam() << '\n';
3959 os << "\\begin{" << style.latexname() << '}'
3960 << style.latexparam() << '\n';
3963 LyXParagraph * par = this;
3965 par = par->TeXOnePar(buf, bparams,
3969 foot, foot_texrow, foot_count
3973 if (minipage_open && par && !style.isEnvironment() &&
3974 (par->pextra_type == PEXTRA_MINIPAGE) &&
3975 par->pextra_start_minipage) {
3976 os << "\\end{minipage}\n";
3978 if (par_sep == BufferParams::PARSEP_INDENT) {
3982 minipage_open = false;
3984 if (par && par->depth > depth) {
3985 if (textclasslist.Style(bparams.textclass,
3986 par->layout).isParagraph()
3991 // How to handle this? (Lgb)
3992 //&& !suffixIs(os, "\n\n")
3994 // There should be at least one '\n' already
3995 // but we need there to be two for Standard
3996 // paragraphs that are depth-increment'ed to be
3997 // output correctly. However, tables can
3998 // also be paragraphs so don't adjust them.
4001 // Will it ever harm to have one '\n' too
4002 // many? i.e. that we sometimes will have
4003 // three in a row. (Lgb)
4007 par = par->TeXDeeper(buf, bparams, os, texrow
4009 ,foot, foot_texrow, foot_count
4013 if (par && par->layout == layout && par->depth == depth &&
4014 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
4015 if (par->pextra_hfill && par->Previous() &&
4016 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
4017 os << "\\hfill{}\n";
4020 if (par_sep == BufferParams::PARSEP_INDENT) {
4021 os << "{\\setlength\\parindent{0pt}\n";
4024 os << "\\begin{minipage}";
4025 switch(par->pextra_alignment) {
4026 case MINIPAGE_ALIGN_TOP:
4029 case MINIPAGE_ALIGN_MIDDLE:
4032 case MINIPAGE_ALIGN_BOTTOM:
4036 if (!par->pextra_width.empty()) {
4037 os << '{' << par->pextra_width << "}\n";
4039 //float ib = atof(par->pextra_widthp.c_str())/100;
4040 // string can't handle floats at present
4041 // so I'll do a conversion by hand knowing that
4042 // the limits are 0.0 to 1.0. ARRae.
4044 switch (par->pextra_widthp.length()) {
4049 os << "0." << par->pextra_widthp;
4052 os << "0.0" << par->pextra_widthp;
4054 os << "\\columnwidth}\n";
4057 if (par_sep == BufferParams::PARSEP_INDENT) {
4058 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
4061 minipage_open = true;
4062 minipage_open_depth = par->depth;
4065 && par->layout == layout
4066 && par->depth == depth
4067 && par->pextra_type == pextra_type
4069 && par->footnoteflag == footnoteflag
4073 if (style.isEnvironment()) {
4074 os << "\\end{" << style.latexname() << '}';
4076 // maybe this should go after the minipage closes?
4077 if (foot_this_level) {
4078 if (foot_count >= 1) {
4079 if (foot_count > 1) {
4080 os << "\\addtocounter{footnote}{-"
4085 texrow += foot_texrow;
4087 foot_texrow.reset();
4093 if (minipage_open && (minipage_open_depth == depth) &&
4094 (!par || par->pextra_start_minipage ||
4095 par->pextra_type != PEXTRA_MINIPAGE)) {
4096 os << "\\end{minipage}\n";
4098 if (par_sep == BufferParams::PARSEP_INDENT) {
4102 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
4103 os << "\\medskip\n\n";
4107 minipage_open = false;
4110 os << "\\end{LyXParagraphIndent}\n";
4113 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
4114 && par->pextra_hfill)) {
4118 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
4119 return par; // ale970302
4124 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
4125 BufferParams const & bparams,
4126 ostream & os, TexRow & texrow,
4127 ostream & foot, TexRow & foot_texrow,
4131 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
4132 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
4133 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4134 "No footnote!" << endl;
4136 LyXParagraph * par = this;
4137 LyXLayout const & style =
4138 textclasslist.Style(bparams.textclass,
4139 previous->GetLayout());
4141 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
4142 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4143 "Float other than footnote in command"
4144 " with moving argument is illegal" << endl;
4147 if (footnotekind != LyXParagraph::FOOTNOTE
4148 && footnotekind != LyXParagraph::MARGIN
4151 // How to solve this?
4152 //&& !suffixIs(file, '\n')
4154 // we need to ensure that real floats like tables and figures
4155 // have their \begin{} on a new line otherwise we can get
4156 // incorrect results when using the endfloat.sty package
4157 // especially if two floats follow one another. ARRae 981022
4158 // NOTE: if the file is length 0 it must have just been
4159 // written out so we assume it ended with a '\n'
4161 // As far as I can see there is never any harm in writing
4162 // a '\n' too much. Please tell me if I am wrong. (Lgb)
4167 bool moving_arg = false;
4168 bool need_closing = false;
4169 bool is_rtl = isRightToLeftPar(bparams);
4171 if (is_rtl != parent_is_rtl) {
4176 need_closing = true;
4179 //BufferParams * params = ¤t_view->buffer()->params;
4180 bool footer_in_body = true;
4181 switch (footnotekind) {
4182 case LyXParagraph::FOOTNOTE:
4183 if (style.intitle) {
4184 os << "\\thanks{\n";
4185 footer_in_body = false;
4188 if (foot_count == -1) {
4189 // we're at depth 0 so we can use:
4190 os << "\\footnote{%\n";
4191 footer_in_body = false;
4193 os << "\\footnotemark{}%\n";
4195 // we only need this when there are
4196 // multiple footnotes
4197 os << "\\stepcounter{footnote}";
4199 os << "\\footnotetext{%\n";
4200 foot_texrow.start(this, 0);
4201 foot_texrow.newline();
4206 case LyXParagraph::MARGIN:
4207 os << "\\marginpar{\n";
4209 case LyXParagraph::FIG:
4210 if (pextra_type == PEXTRA_FLOATFLT
4211 && (!pextra_width.empty()
4212 || !pextra_widthp.empty())) {
4213 if (!pextra_width.empty())
4214 os << "\\begin{floatingfigure}{"
4215 << pextra_width << "}\n";
4217 os << "\\begin{floatingfigure}{"
4218 << atoi(pextra_widthp.c_str())/100.0
4219 << "\\textwidth}\n";
4221 os << "\\begin{figure}";
4222 if (!bparams.float_placement.empty()) {
4223 os << '[' << bparams.float_placement << "]\n";
4229 case LyXParagraph::TAB:
4230 os << "\\begin{table}";
4231 if (!bparams.float_placement.empty()) {
4232 os << '[' << bparams.float_placement << "]\n";
4237 case LyXParagraph::WIDE_FIG:
4238 os << "\\begin{figure*}";
4239 if (!bparams.float_placement.empty()) {
4240 os << '[' << bparams.float_placement << "]\n";
4245 case LyXParagraph::WIDE_TAB:
4246 os << "\\begin{table*}";
4247 if (!bparams.float_placement.empty()) {
4248 os << '[' << bparams.float_placement << "]\n";
4253 case LyXParagraph::ALGORITHM:
4254 os << "\\begin{algorithm}\n";
4259 if (footnotekind != LyXParagraph::FOOTNOTE
4260 || !footer_in_body) {
4261 // Process text for all floats except footnotes in body
4263 LyXLayout const & style =
4265 .Style(bparams.textclass, par->layout);
4267 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4269 if (style.isEnvironment()
4270 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4271 // Allows the use of minipages within float
4272 // environments. Shouldn't be circular because
4273 // we don't support footnotes inside
4274 // floats (yet). ARRae
4275 par = par->TeXEnvironment(buf, bparams, os,
4280 par = par->TeXOnePar(buf, bparams,
4281 os, texrow, moving_arg,
4286 if (par && !par->IsDummy() && par->depth > depth) {
4287 par = par->TeXDeeper(buf, bparams, os, texrow,
4291 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4293 // process footnotes > depth 0 or in environments separately
4294 // NOTE: Currently don't support footnotes within footnotes
4295 // even though that is possible using the \footnotemark
4297 std::ostringstream dummy;
4301 TexRow dummy_texrow;
4302 int dummy_count = 0;
4304 LyXLayout const & style =
4306 .Style(bparams.textclass, par->layout);
4308 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4310 if (style.isEnvironment()
4311 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4312 // Allows the use of minipages within float
4313 // environments. Shouldn't be circular because
4314 // we don't support footnotes inside
4315 // floats (yet). ARRae
4316 par = par->TeXEnvironment(buf, bparams,
4318 dummy, dummy_texrow,
4321 par = par->TeXOnePar(buf, bparams,
4324 dummy, dummy_texrow,
4328 if (par && !par->IsDummy() && par->depth > depth) {
4329 par = par->TeXDeeper(buf, bparams,
4331 dummy, dummy_texrow,
4335 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4337 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4338 "Footnote in a Footnote -- not supported"
4341 #ifndef HAVE_OSTREAM
4342 delete [] dummy.str();
4346 switch (footnotekind) {
4347 case LyXParagraph::FOOTNOTE:
4348 if (footer_in_body) {
4349 // This helps tell which of the multiple
4350 // footnotetexts an error was in.
4352 foot_texrow.newline();
4357 case LyXParagraph::MARGIN:
4360 case LyXParagraph::FIG:
4361 if (pextra_type == PEXTRA_FLOATFLT
4362 && (!pextra_width.empty()
4363 || !pextra_widthp.empty()))
4364 os << "\\end{floatingfigure}";
4366 os << "\\end{figure}";
4368 case LyXParagraph::TAB:
4369 os << "\\end{table}";
4371 case LyXParagraph::WIDE_FIG:
4372 os << "\\end{figure*}";
4374 case LyXParagraph::WIDE_TAB:
4375 os << "\\end{table*}";
4377 case LyXParagraph::ALGORITHM:
4378 os << "\\end{algorithm}";
4385 if (footnotekind != LyXParagraph::FOOTNOTE
4386 && footnotekind != LyXParagraph::MARGIN) {
4387 // we need to ensure that real floats like tables and figures
4388 // have their \end{} on a line of their own otherwise we can
4389 // get incorrect results when using the endfloat.sty package.
4394 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4399 bool LyXParagraph::IsDummy() const
4401 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4402 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4406 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4407 int type, char const * width,
4408 char const * widthp)
4411 pextra_width = width;
4412 pextra_widthp = widthp;
4414 if (textclasslist.Style(bparams.textclass,
4415 layout).isEnvironment()) {
4416 LyXParagraph * par = this;
4417 LyXParagraph * ppar = par;
4419 while (par && (par->layout == layout)
4420 && (par->depth == depth)) {
4422 par = par->Previous();
4425 par = par->FirstPhysicalPar();
4427 while (par && par->depth > depth) {
4428 par = par->Previous();
4431 par = par->FirstPhysicalPar();
4436 while (par && (par->layout == layout)
4437 && (par->depth == depth)) {
4438 par->pextra_type = type;
4439 par->pextra_width = width;
4440 par->pextra_widthp = widthp;
4442 par = par->NextAfterFootnote();
4446 if (par && (par->depth > depth))
4447 par->SetPExtraType(bparams,
4448 type, width, widthp);
4450 while (par && ((par->depth > depth) || par->IsDummy()))
4451 par = par->NextAfterFootnote();
4453 while (par && ((par->depth > depth)))
4461 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4463 if (pextra_type == PEXTRA_NONE)
4466 pextra_type = PEXTRA_NONE;
4467 pextra_width.erase();
4468 pextra_widthp.erase();
4470 if (textclasslist.Style(bparams.textclass,
4471 layout).isEnvironment()) {
4472 LyXParagraph * par = this;
4473 LyXParagraph * ppar = par;
4475 while (par && (par->layout == layout)
4476 && (par->depth == depth)) {
4478 par = par->Previous();
4481 par = par->FirstPhysicalPar();
4483 while (par && par->depth > depth) {
4484 par = par->Previous();
4487 par = par->FirstPhysicalPar();
4492 while (par && (par->layout == layout)
4493 && (par->depth == depth)) {
4494 par->pextra_type = PEXTRA_NONE;
4495 par->pextra_width.erase();
4496 par->pextra_widthp.erase();
4498 par = par->NextAfterFootnote();
4502 if (par && (par->depth > depth))
4503 par->UnsetPExtraType(bparams);
4505 while (par && ((par->depth > depth) || par->IsDummy()))
4506 par = par->NextAfterFootnote();
4508 while (par && ((par->depth > depth)))
4516 bool LyXParagraph::IsHfill(size_type pos) const
4518 return IsHfillChar(GetChar(pos));
4522 bool LyXParagraph::IsInset(size_type pos) const
4524 return IsInsetChar(GetChar(pos));
4529 bool LyXParagraph::IsFloat(size_type pos) const
4531 return IsFloatChar(GetChar(pos));
4536 bool LyXParagraph::IsNewline(size_type pos) const
4538 return pos >= 0 && IsNewlineChar(GetChar(pos));
4542 bool LyXParagraph::IsSeparator(size_type pos) const
4544 return IsSeparatorChar(GetChar(pos));
4548 bool LyXParagraph::IsLineSeparator(size_type pos) const
4550 return IsLineSeparatorChar(GetChar(pos));
4554 bool LyXParagraph::IsKomma(size_type pos) const
4556 return IsKommaChar(GetChar(pos));
4560 /// Used by the spellchecker
4561 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4563 value_type c = GetChar(pos);
4564 if (IsLetterChar(c))
4566 // '\0' is not a letter, allthough every string contains "" (below)
4569 // We want to pass the ' and escape chars to ispell
4570 string extra = lyxrc.isp_esc_chars + '\'';
4571 char ch[2] = { c, 0 };
4572 return contains(extra, ch);
4576 bool LyXParagraph::IsWord(size_type pos ) const
4578 return IsWordChar(GetChar(pos)) ;
4583 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4587 return FirstPhysicalPar()->getParLanguage(bparams);
4594 return GetFirstFontSettings().language();
4597 for (size_type pos = 0; pos < size(); ++pos)
4599 return GetFontSettings(bparams, pos).language();
4600 return GetFirstFontSettings().language();
4604 return previous->getParLanguage(bparams);
4606 return bparams.language_info;
4610 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4612 return lyxrc.rtl_support
4616 && getParLanguage(bparams)->RightToLeft();
4620 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4621 Language const * from, Language const * to)
4623 for(size_type i = 0; i < size(); ++i) {
4624 LyXFont font = GetFontSettings(bparams, i);
4625 if (font.language() == from) {
4626 font.setLanguage(to);
4633 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4635 Language const * doc_language = bparams.language_info;
4636 for (FontList::const_iterator cit = fontlist.begin();
4637 cit != fontlist.end(); ++cit)
4638 if ((*cit).font.language() != doc_language)
4644 // Convert the paragraph to a string.
4645 // Used for building the table of contents
4646 string LyXParagraph::String(Buffer const * buffer, bool label)
4648 BufferParams const & bparams = buffer->params;
4651 if (label && !IsDummy() && !labelstring.empty())
4653 if (label && !labelstring.empty())
4655 s += labelstring + ' ';
4656 string::size_type len = s.size();
4658 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4659 value_type c = GetChar(i);
4662 else if (c == META_INSET &&
4663 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4665 std::ostringstream ost;
4666 GetInset(i)->Ascii(buffer, ost);
4669 GetInset(i)->Ascii(buffer, ost);
4672 s += subst(ost.str(),'\n',' ');
4677 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4678 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4679 s += NextAfterFootnote()->String(buffer, false);
4683 if (isRightToLeftPar(bparams))
4684 reverse(s.begin() + len,s.end());
4692 string LyXParagraph::String(Buffer const * buffer,
4693 LyXParagraph::size_type beg,
4694 LyXParagraph::size_type end)
4701 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4703 if (cell >= table->NumberOfCellsInRow(actcell))
4712 if (beg == 0 && !IsDummy() && !labelstring.empty())
4714 if (beg == 0 && !labelstring.empty())
4716 s += labelstring + ' ';
4718 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4719 value_type c = GetChar(i);
4722 else if (c == META_INSET) {
4724 std::ostringstream ost;
4725 GetInset(i)->Ascii(buffer, ost);
4728 GetInset(i)->Ascii(buffer, ost);
4734 else if (table && IsNewlineChar(c)) {
4735 if (cell >= table->NumberOfCellsInRow(actcell)) {
4751 void LyXParagraph::SetInsetOwner(Inset *i)
4754 for (InsetList::const_iterator cit = insetlist.begin();
4755 cit != insetlist.end(); ++cit) {
4757 (*cit).inset->setOwner(i);
4762 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4765 for (InsetList::const_iterator cit = insetlist.begin();
4766 cit != insetlist.end(); ++cit) {
4768 if ((*cit).inset->IsTextInset()) {
4769 static_cast<UpdatableInset *>
4770 ((*cit).inset)->deleteLyXText(bv);
4777 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4780 for (InsetList::const_iterator cit = insetlist.begin();
4781 cit != insetlist.end(); ++cit) {
4783 if ((*cit).inset->IsTextInset()) {
4784 static_cast<UpdatableInset *>
4785 ((*cit).inset)->resizeLyXText(bv);