1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
25 #include "tex-strings.h"
26 #include "bufferparams.h"
27 #include "support/FileInfo.h"
28 #include "support/LAssert.h"
30 #include "LaTeXFeatures.h"
31 #include "insets/insetinclude.h"
32 #include "insets/insetbib.h"
33 #include "insets/insettext.h"
34 #include "support/filetools.h"
35 #include "lyx_gui_misc.h"
37 #include "support/lyxmanip.h"
38 #include "BufferView.h"
45 using std::lower_bound;
46 using std::upper_bound;
49 int tex_code_break_column = 72; // needs non-zero initialization. set later.
50 // this is a bad idea, but how can LyXParagraph find its buffer to get
51 // parameters? (JMarc)
52 extern BufferView * current_view;
53 extern string bibitemWidest(BufferView *);
55 // this is a minibuffer
56 static char minibuffer_char;
57 static LyXFont minibuffer_font;
58 static Inset * minibuffer_inset;
61 // Initialization of the counter for the paragraph id's,
62 // declared in lyxparagraph.h
63 unsigned int LyXParagraph::paragraph_id = 0;
66 LyXParagraph::LyXParagraph()
68 text.reserve(500); // is this number too big?
70 for (int i = 0; i < 10; ++i) setCounter(i , 0);
77 footnoteflag = LyXParagraph::NO_FOOTNOTE;
78 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
80 align = LYX_ALIGN_BLOCK;
83 /* table stuff -- begin*/
85 /* table stuff -- end*/
89 bibkey = 0; // ale970302
94 // This konstruktor inserts the new paragraph in a list.
95 LyXParagraph::LyXParagraph(LyXParagraph * par)
98 par->text.resize(par->text.size());
100 for (int i = 0; i < 10; ++i) setCounter(i, 0);
104 // double linked list begin
107 next->previous = this;
109 previous->next = this;
112 footnoteflag = LyXParagraph::NO_FOOTNOTE;
113 footnotekind = LyXParagraph::FOOTNOTE;
116 /* table stuff -- begin*/
118 /* table stuff -- end*/
121 id_ = paragraph_id++;
123 bibkey = 0; // ale970302
129 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
130 BufferParams const & params,
131 char footflag, char dth) const
135 footnoteflag != LyXParagraph::NO_FOOTNOTE ||
137 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
142 // The beginning or the end of a footnote environment?
143 if (footflag != footnoteflag) {
144 footflag = footnoteflag;
146 os << "\n\\begin_float "
147 << string_footnotekinds[footnotekind]
150 os << "\n\\end_float ";
154 // The beginning or end of a deeper (i.e. nested) area?
157 while (depth > dth) {
158 os << "\n\\begin_deeper ";
162 while (depth < dth) {
163 os << "\n\\end_deeper ";
169 // First write the layout
171 << textclasslist.NameOfLayout(params.textclass, layout)
174 // Maybe some vertical spaces.
175 if (added_space_top.kind() != VSpace::NONE)
176 os << "\\added_space_top "
177 << added_space_top.asLyXCommand() << " ";
178 if (added_space_bottom.kind() != VSpace::NONE)
179 os << "\\added_space_bottom "
180 << added_space_bottom.asLyXCommand() << " ";
182 // Maybe the paragraph has special spacing
183 spacing.writeFile(os, true);
185 // The labelwidth string used in lists.
186 if (!labelwidthstring.empty())
187 os << "\\labelwidthstring "
188 << labelwidthstring << '\n';
190 // Lines above or below?
194 os << "\\line_bottom ";
196 // Pagebreaks above or below?
198 os << "\\pagebreak_top ";
199 if (pagebreak_bottom)
200 os << "\\pagebreak_bottom ";
202 // Start of appendix?
203 if (start_of_appendix)
204 os << "\\start_of_appendix ";
211 if (align != LYX_ALIGN_LAYOUT) {
214 case LYX_ALIGN_LEFT: h = 1; break;
215 case LYX_ALIGN_RIGHT: h = 2; break;
216 case LYX_ALIGN_CENTER: h = 3; break;
217 default: h = 0; break;
219 os << "\\align " << string_align[h] << " ";
221 if (pextra_type != PEXTRA_NONE) {
222 os << "\\pextra_type " << pextra_type;
223 if (pextra_type == PEXTRA_MINIPAGE) {
224 os << " \\pextra_alignment "
227 os << " \\pextra_hfill "
229 if (pextra_start_minipage)
230 os << " \\pextra_start_minipage "
231 << pextra_start_minipage;
233 if (!pextra_width.empty()) {
234 os << " \\pextra_width "
235 << VSpace(pextra_width).asLyXCommand();
236 } else if (!pextra_widthp.empty()) {
237 os << " \\pextra_widthp "
244 // Dummy layout. This means that a footnote ended.
245 os << "\n\\end_float ";
246 footflag = LyXParagraph::NO_FOOTNOTE;
250 // It might be a table.
252 os << "\\LyXTable\n";
258 bibkey->Write(buf, os);
260 LyXFont font1(LyXFont::ALL_INHERIT, params.language_info);
263 for (size_type i = 0; i < size(); ++i) {
269 // Write font changes
270 LyXFont font2 = GetFontSettings(params, i);
271 if (font2 != font1) {
272 font2.lyxWriteChanges(font1, os);
277 value_type c = GetChar(i);
281 Inset const * inset = GetInset(i);
283 if (inset->DirectWrite()) {
284 // international char, let it write
285 // code directly so it's shorter in
287 inset->Write(buf, os);
289 os << "\n\\begin_inset ";
290 inset->Write(buf, os);
291 os << "\n\\end_inset \n\n";
297 os << "\n\\newline \n";
301 os << "\n\\hfill \n";
305 os << "\n\\backslash \n";
309 if (i + 1 < size() && GetChar(i + 1) == ' ') {
316 if ((column > 70 && c == ' ')
321 // this check is to amend a bug. LyX sometimes
322 // inserts '\0' this could cause problems.
326 lyxerr << "ERROR (LyXParagraph::writeFile):"
327 " NULL char in structure." << endl;
333 // now write the next paragraph
335 next->writeFile(buf, os, params, footflag, dth);
339 void LyXParagraph::validate(LaTeXFeatures & features) const
341 BufferParams const & params = features.bufferParams();
344 // this will be useful later
345 LyXLayout const & layout =
346 textclasslist.Style(params.textclass,
351 if (line_top || line_bottom)
352 features.lyxline = true;
353 if (!spacing.isDefault())
354 features.setspace = true;
357 features.layout[GetLayout()] = true;
360 Language const * doc_language = params.language_info;
362 for (FontList::const_iterator cit = fontlist.begin();
363 cit != fontlist.end(); ++cit) {
364 if ((*cit).font.noun() == LyXFont::ON) {
365 lyxerr[Debug::LATEX] << "font.noun: "
366 << (*cit).font.noun()
368 features.noun = true;
369 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
370 << (*cit).font.stateText(0)
373 switch ((*cit).font.color()) {
375 case LColor::inherit:
379 features.color = true;
380 lyxerr[Debug::LATEX] << "Color enabled. Font: "
381 << (*cit).font.stateText(0)
385 Language const * language = (*cit).font.language();
386 if (language != doc_language) {
387 features.UsedLanguages.insert(language);
388 lyxerr[Debug::LATEX] << "Found language "
389 << language->lang() << endl;
394 for (InsetList::const_iterator cit = insetlist.begin();
395 cit != insetlist.end(); ++cit) {
397 (*cit).inset->Validate(features);
400 if (table && table->IsLongTable())
401 features.longtable = true;
402 if (pextra_type == PEXTRA_INDENT)
403 features.LyXParagraphIndent = true;
404 if (pextra_type == PEXTRA_FLOATFLT)
405 features.floatflt = true;
407 if (layout.needprotect
408 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
409 features.NeedLyXFootnoteCode = true;
411 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
412 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
413 features.NeedLyXMinipageIndent = true;
414 if (table && table->NeedRotating())
415 features.rotating = true;
417 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
418 features.algorithm = true;
423 // First few functions needed for cut and paste and paragraph breaking.
424 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
425 LyXParagraph::size_type pos) const
427 minibuffer_char = GetChar(pos);
428 minibuffer_font = GetFontSettings(bparams, pos);
429 minibuffer_inset = 0;
430 if (minibuffer_char == LyXParagraph::META_INSET) {
432 minibuffer_inset = GetInset(pos)->Clone();
434 minibuffer_inset = 0;
435 minibuffer_char = ' ';
436 // This reflects what GetInset() does (ARRae)
442 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
443 LyXParagraph::size_type pos)
445 minibuffer_char = GetChar(pos);
446 minibuffer_font = GetFontSettings(bparams, pos);
447 minibuffer_inset = 0;
448 if (minibuffer_char == LyXParagraph::META_INSET) {
450 minibuffer_inset = GetInset(pos);
451 // This is a little hack since I want exactly
452 // the inset, not just a clone. Otherwise
453 // the inset would be deleted when calling Erase(pos)
455 InsetTable search_elem(pos, 0);
456 InsetList::iterator it =
457 lower_bound(insetlist.begin(),
459 search_elem, matchIT());
460 if (it != insetlist.end() && (*it).pos == pos)
463 minibuffer_inset = 0;
464 minibuffer_char = ' ';
465 // This reflects what GetInset() does (ARRae)
470 // Erase(pos); now the caller is responsible for that.
474 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
476 if ((minibuffer_char == LyXParagraph::META_INSET) &&
477 !InsertInsetAllowed(minibuffer_inset))
479 if (minibuffer_char == LyXParagraph::META_INSET)
480 InsertInset(pos, minibuffer_inset, minibuffer_font);
482 InsertChar(pos, minibuffer_char, minibuffer_font);
490 void LyXParagraph::Clear()
495 pagebreak_top = false;
496 pagebreak_bottom = false;
498 added_space_top = VSpace(VSpace::NONE);
499 added_space_bottom = VSpace(VSpace::NONE);
500 spacing.set(Spacing::Default);
502 align = LYX_ALIGN_LAYOUT;
506 pextra_type = PEXTRA_NONE;
507 pextra_width.erase();
508 pextra_widthp.erase();
509 pextra_alignment = MINIPAGE_ALIGN_TOP;
510 pextra_hfill = false;
511 pextra_start_minipage = false;
514 labelwidthstring.erase();
518 start_of_appendix = false;
522 // the destructor removes the new paragraph from the list
523 LyXParagraph::~LyXParagraph()
526 previous->next = next;
528 next->previous = previous;
530 for (InsetList::iterator it = insetlist.begin();
531 it != insetlist.end(); ++it) {
535 /* table stuff -- begin*/
537 /* table stuff -- end*/
543 //lyxerr << "LyXParagraph::paragraph_id = "
544 // << LyXParagraph::paragraph_id << endl;
548 void LyXParagraph::Erase(LyXParagraph::size_type pos)
550 // > because last is the next unused position, and you can
551 // use it if you want
554 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
555 NextAfterFootnote()->Erase(pos - text.size() - 1);
558 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
559 "position does not exist." << endl;
562 if (pos < size()) { // last is free for insertation, but should be empty
563 // if it is an inset, delete the inset entry
564 if (text[pos] == LyXParagraph::META_INSET) {
566 InsetTable search_inset(pos, 0);
567 InsetList::iterator it =
568 lower_bound(insetlist.begin(),
570 search_inset, matchIT());
571 if (it != insetlist.end() && (*it).pos == pos) {
576 text.erase(text.begin() + pos);
578 // Erase entries in the tables.
579 FontTable search_font(pos, LyXFont());
581 FontList::iterator it =
582 lower_bound(fontlist.begin(),
584 search_font, matchFT());
585 if (it != fontlist.end() && (*it).pos == pos &&
587 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
588 // If it is a multi-character font
589 // entry, we just make it smaller
590 // (see update below), otherwise we
592 unsigned int i = it - fontlist.begin();
593 fontlist.erase(fontlist.begin() + i);
594 it = fontlist.begin() + i;
595 if (i > 0 && i < fontlist.size() &&
596 fontlist[i-1].font == fontlist[i].font) {
597 fontlist.erase(fontlist.begin() + i-1);
598 it = fontlist.begin() + i-1;
602 // Update all other entries.
603 for (; it != fontlist.end(); ++it)
606 // Update the inset table.
607 InsetTable search_inset(pos, 0);
608 for (InsetList::iterator it =
609 upper_bound(insetlist.begin(),
611 search_inset, matchIT());
612 it != insetlist.end(); ++it)
615 lyxerr << "ERROR (LyXParagraph::Erase): "
616 "can't erase non-existant char." << endl;
621 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
622 LyXParagraph::value_type c)
624 LyXFont f(LyXFont::ALL_INHERIT);
625 InsertChar(pos, c, f);
629 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
630 LyXParagraph::value_type c,
631 LyXFont const & font)
633 // > because last is the next unused position, and you can
634 // use it if you want
638 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
639 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
643 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
644 "position does not exist." << endl;
647 text.insert(text.begin() + pos, c);
648 // Update the font table.
649 FontTable search_font(pos, LyXFont());
650 for (FontList::iterator it = lower_bound(fontlist.begin(),
652 search_font, matchFT());
653 it != fontlist.end(); ++it)
656 // Update the inset table.
657 InsetTable search_inset(pos, 0);
658 for (InsetList::iterator it = lower_bound(insetlist.begin(),
660 search_inset, matchIT());
661 it != insetlist.end(); ++it)
668 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
671 LyXFont f(LyXFont::ALL_INHERIT);
672 InsertInset(pos, inset, f);
676 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
677 Inset * inset, LyXFont const & font)
681 // > because last is the next unused position, and you can
682 // use it if you want
686 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
688 ->InsertInset(pos - text.size() - 1,
692 lyxerr << "ERROR (LyXParagraph::InsertInset): "
693 "position does not exist: " << pos << endl;
697 InsertChar(pos, META_INSET, font);
698 Assert(text[pos] == META_INSET);
700 // Add a new entry in the inset table.
701 InsetTable search_inset(pos, 0);
702 InsetList::iterator it = lower_bound(insetlist.begin(),
704 search_inset, matchIT());
705 if (it != insetlist.end() && (*it).pos == pos)
706 lyxerr << "ERROR (LyXParagraph::InsertInset): "
707 "there is an inset in position: " << pos << endl;
709 insetlist.insert(it, InsetTable(pos, inset));
711 inset->setOwner(inset_owner);
715 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
717 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
720 return inset_owner->InsertInsetAllowed(inset);
725 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
730 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
731 return NextAfterFootnote()
732 ->GetInset(pos - text.size() - 1);
735 lyxerr << "ERROR (LyXParagraph::GetInset): "
736 "position does not exist: "
742 InsetTable search_inset(pos, 0);
743 InsetList::iterator it = lower_bound(insetlist.begin(),
745 search_inset, matchIT());
746 if (it != insetlist.end() && (*it).pos == pos)
749 lyxerr << "ERROR (LyXParagraph::GetInset): "
750 "Inset does not exist: " << pos << endl;
753 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
754 // Did this commenting out introduce a bug? So far I have not
755 // see any, please enlighten me. (Lgb)
756 // My guess is that since the inset does not exist, we might
757 // as well replace it with a space to prevent craches. (Asger)
762 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
767 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
768 return NextAfterFootnote()
769 ->GetInset(pos - text.size() - 1);
772 lyxerr << "ERROR (LyXParagraph::GetInset): "
773 "position does not exist: "
779 InsetTable search_inset(pos, 0);
780 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
782 search_inset, matchIT());
783 if (cit != insetlist.end() && (*cit).pos == pos)
786 lyxerr << "ERROR (LyXParagraph::GetInset): "
787 "Inset does not exist: " << pos << endl;
789 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
790 // Did this commenting out introduce a bug? So far I have not
791 // see any, please enlighten me. (Lgb)
792 // My guess is that since the inset does not exist, we might
793 // as well replace it with a space to prevent craches. (Asger)
798 // Gets uninstantiated font setting at position.
799 // Optimized after profiling. (Asger)
800 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
801 LyXParagraph::size_type pos) const
804 FontTable search_font(pos, LyXFont());
805 FontList::const_iterator cit = lower_bound(fontlist.begin(),
807 search_font, matchFT());
808 if (cit != fontlist.end())
811 // > because last is the next unused position, and you can
812 // use it if you want
813 else if (pos > size()) {
816 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
817 return NextAfterFootnote()
818 ->GetFontSettings(bparams,
819 pos - text.size() - 1);
822 // Why is it an error to ask for the font of a
823 // position that does not exist? Would it be
824 // enough for this to be enabled on debug?
825 // We want strict error checking, but it's ok to only
826 // have it when debugging. (Asger)
827 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
828 "position does not exist. "
829 << pos << " (" << static_cast<int>(pos)
831 } else if (pos > 0) {
832 return GetFontSettings(bparams, pos - 1);
833 } else // pos = size() = 0
834 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
836 return LyXFont(LyXFont::ALL_INHERIT);
839 // Gets uninstantiated font setting at position 0
840 LyXFont LyXParagraph::GetFirstFontSettings() const
843 if (!fontlist.empty())
844 return fontlist[0].font;
848 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
849 return NextAfterFootnote()->GetFirstFontSettings();
851 return LyXFont(LyXFont::ALL_INHERIT);
855 // Gets the fully instantiated font at a given position in a paragraph
856 // This is basically the same function as LyXText::GetFont() in text2.C.
857 // The difference is that this one is used for generating the LaTeX file,
858 // and thus cosmetic "improvements" are disallowed: This has to deliver
859 // the true picture of the buffer. (Asger)
860 // If position is -1, we get the layout font of the paragraph.
861 // If position is -2, we get the font of the manual label of the paragraph.
862 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
863 LyXParagraph::size_type pos) const
866 LyXLayout const & layout =
867 textclasslist.Style(bparams.textclass,
869 LyXParagraph::size_type main_body = 0;
870 if (layout.labeltype == LABEL_MANUAL)
871 main_body = BeginningOfMainBody();
876 layoutfont = layout.labelfont;
878 layoutfont = layout.font;
879 tmpfont = GetFontSettings(bparams, pos);
880 tmpfont.realize(layoutfont);
882 // process layoutfont for pos == -1 and labelfont for pos < -1
884 tmpfont = layout.font;
886 tmpfont = layout.labelfont;
887 tmpfont.setLanguage(getParLanguage(bparams));
890 // check for environment font information
891 char par_depth = GetDepth();
892 LyXParagraph const * par = this;
893 while (par && par_depth && !tmpfont.resolved()) {
894 par = par->DepthHook(par_depth - 1);
896 tmpfont.realize(textclasslist.
897 Style(bparams.textclass,
898 par->GetLayout()).font);
899 par_depth = par->GetDepth();
903 tmpfont.realize(textclasslist
904 .TextClass(bparams.textclass)
910 /// Returns the height of the highest font in range
912 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
913 LyXParagraph::size_type endpos) const
915 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
916 if (fontlist.empty())
919 FontTable end_search(endpos, LyXFont());
920 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
922 end_search, matchFT());
923 if (end_it != fontlist.end())
926 FontTable start_search(startpos, LyXFont());
927 for (FontList::const_iterator cit =
928 lower_bound(fontlist.begin(),
930 start_search, matchFT());
931 cit != end_it; ++cit) {
932 LyXFont::FONT_SIZE size = (*cit).font.size();
933 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
940 LyXParagraph::value_type
941 LyXParagraph::GetChar(LyXParagraph::size_type pos)
948 // > because last is the next unused position, and you can
949 // use it if you want
950 else if (pos > size()) {
952 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
953 return NextAfterFootnote()
954 ->GetChar(pos - text.size() - 1);
958 lyxerr << "ERROR (LyXParagraph::GetChar): "
959 "position does not exist."
960 << pos << " (" << static_cast<int>(pos)
962 // Assert(false); // This triggers sometimes...
971 // We should have a footnote environment.
972 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
973 // Notice that LyX does request the
974 // last char from time to time. (Asger)
975 //lyxerr << "ERROR (LyXParagraph::GetChar): "
976 // "expected footnote." << endl;
979 switch (next->footnotekind) {
980 case LyXParagraph::FOOTNOTE:
981 return LyXParagraph::META_FOOTNOTE;
982 case LyXParagraph::MARGIN:
983 return LyXParagraph::META_MARGIN;
984 case LyXParagraph::FIG:
985 case LyXParagraph::WIDE_FIG:
986 return LyXParagraph::META_FIG;
987 case LyXParagraph::TAB:
988 case LyXParagraph::WIDE_TAB:
989 return LyXParagraph::META_TAB;
990 case LyXParagraph::ALGORITHM:
991 return LyXParagraph::META_ALGORITHM;
993 return '\0'; // to shut up gcc
996 return '\0'; // to shut up gcc
1001 LyXParagraph::value_type
1002 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
1009 // > because last is the next unused position, and you can
1010 // use it if you want
1011 else if (pos > size()) {
1013 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1014 return NextAfterFootnote()
1015 ->GetChar(pos - text.size() - 1);
1019 lyxerr << "ERROR (LyXParagraph::GetChar const): "
1020 "position does not exist."
1021 << pos << " (" << static_cast<int>(pos)
1029 // We should have a footnote environment.
1030 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1031 // Notice that LyX does request the
1032 // last char from time to time. (Asger)
1033 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1034 // "expected footnote." << endl;
1037 switch (next->footnotekind) {
1038 case LyXParagraph::FOOTNOTE:
1039 return LyXParagraph::META_FOOTNOTE;
1040 case LyXParagraph::MARGIN:
1041 return LyXParagraph::META_MARGIN;
1042 case LyXParagraph::FIG:
1043 case LyXParagraph::WIDE_FIG:
1044 return LyXParagraph::META_FIG;
1045 case LyXParagraph::TAB:
1046 case LyXParagraph::WIDE_TAB:
1047 return LyXParagraph::META_TAB;
1048 case LyXParagraph::ALGORITHM:
1049 return LyXParagraph::META_ALGORITHM;
1051 return '\0'; // to shut up gcc
1054 return '\0'; // to shut up gcc
1060 // return an string of the current word, and the end of the word in lastpos.
1061 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1065 // the current word is defined as starting at the first character
1066 // from the immediate left of lastpospos which meets the definition
1067 // of IsLetter(), continuing to the last character to the right
1068 // of this meeting IsLetter.
1074 // move back until we have a letter
1076 //there's no real reason to have firstpos & lastpos as
1077 //separate variables as this is written, but maybe someon
1078 // will want to return firstpos in the future.
1080 //since someone might have typed a punctuation first
1081 int firstpos = lastpos;
1083 while ((firstpos >= 0) && !IsLetter(firstpos))
1086 // now find the beginning by looking for a nonletter
1088 while ((firstpos>= 0) && IsLetter(firstpos))
1091 // the above is now pointing to the preceeding non-letter
1095 // so copy characters into theword until we get a nonletter
1096 // note that this can easily exceed lastpos, wich means
1097 // that if used in the middle of a word, the whole word
1100 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1107 LyXParagraph::size_type LyXParagraph::Last() const
1110 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1111 return text.size() + NextAfterFootnote()->Last() + 1;
1112 // the 1 is the symbol
1120 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1122 // > because last is the next unused position, and you can
1123 // use it if you want
1127 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1128 return NextAfterFootnote()
1129 ->ParFromPos(pos - text.size() - 1);
1132 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1133 "position does not exist." << endl;
1140 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1142 // > because last is the next unused position, and you can
1143 // use it if you want
1147 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1148 return NextAfterFootnote()
1149 ->PositionInParFromPos(pos - text.size() - 1);
1153 "ERROR (LyXParagraph::PositionInParFromPos): "
1154 "position does not exist." << endl;
1162 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1163 LyXFont const & font)
1165 // > because last is the next unused position, and you can
1166 // use it if you want
1170 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1171 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1175 lyxerr << "ERROR (LyXParagraph::SetFont): "
1176 "position does not exist." << endl;
1181 // First, reduce font against layout/label font
1182 // Update: The SetCharFont() routine in text2.C already
1183 // reduces font, so we don't need to do that here. (Asger)
1184 // No need to simplify this because it will disappear
1185 // in a new kernel. (Asger)
1186 // Next search font table
1188 FontTable search_font(pos, LyXFont());
1189 FontList::iterator it = lower_bound(fontlist.begin(),
1191 search_font, matchFT());
1192 unsigned int i = it - fontlist.begin();
1193 bool notfound = it == fontlist.end();
1195 if (!notfound && fontlist[i].font == font)
1198 bool begin = pos == 0 || notfound ||
1199 (i > 0 && fontlist[i-1].pos == pos - 1);
1200 // Is position pos is a beginning of a font block?
1201 bool end = !notfound && fontlist[i].pos == pos;
1202 // Is position pos is the end of a font block?
1203 if (begin && end) { // A single char block
1204 if (i+1 < fontlist.size() &&
1205 fontlist[i+1].font == font) {
1206 // Merge the singleton block with the next block
1207 fontlist.erase(fontlist.begin() + i);
1208 if (i > 0 && fontlist[i-1].font == font)
1209 fontlist.erase(fontlist.begin() + i-1);
1210 } else if (i > 0 && fontlist[i-1].font == font) {
1211 // Merge the singleton block with the previous block
1212 fontlist[i-1].pos = pos;
1213 fontlist.erase(fontlist.begin() + i);
1215 fontlist[i].font = font;
1217 if (i > 0 && fontlist[i-1].font == font)
1218 fontlist[i-1].pos = pos;
1220 fontlist.insert(fontlist.begin() + i,
1221 FontTable(pos, font));
1223 fontlist[i].pos = pos - 1;
1224 if (!(i+1 < fontlist.size() &&
1225 fontlist[i+1].font == font))
1226 fontlist.insert(fontlist.begin() + i+1,
1227 FontTable(pos, font));
1228 } else { // The general case. The block is splitted into 3 blocks
1229 fontlist.insert(fontlist.begin() + i,
1230 FontTable(pos - 1, fontlist[i].font));
1231 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1236 // This function is able to hide closed footnotes.
1237 LyXParagraph * LyXParagraph::Next()
1240 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1241 LyXParagraph * tmp = next;
1243 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1245 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1246 return tmp->Next(); /* there can be more than one
1247 footnote in a logical
1250 return next; // This should never happen!
1258 LyXParagraph * LyXParagraph::NextAfterFootnote()
1260 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1261 LyXParagraph * tmp = next;
1262 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1264 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1265 return tmp; /* there can be more than one footnote
1266 in a logical paragraph */
1268 return next; // This should never happen!
1276 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1278 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1279 LyXParagraph * tmp = next;
1280 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1282 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1283 return tmp; /* there can be more than one footnote
1284 in a logical paragraph */
1286 return next; // This should never happen!
1294 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1297 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1299 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1300 tmp = tmp->previous;
1301 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1302 return tmp; /* there can be more than one footnote
1303 in a logical paragraph */
1305 return previous; // This should never happen!
1313 LyXParagraph * LyXParagraph::LastPhysicalPar()
1315 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1318 LyXParagraph * tmp = this;
1320 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1321 tmp = tmp->NextAfterFootnote();
1329 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1331 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1334 LyXParagraph const * tmp = this;
1336 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1337 tmp = tmp->NextAfterFootnote();
1345 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1349 LyXParagraph * tmppar = this;
1353 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1354 tmppar = tmppar->previous;
1365 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1369 LyXParagraph const * tmppar = this;
1373 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1374 tmppar = tmppar->previous;
1384 // This function is able to hide closed footnotes.
1385 LyXParagraph * LyXParagraph::Previous()
1388 LyXParagraph * tmp = previous;
1393 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1394 tmp = tmp->previous;
1396 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1397 tmp = tmp->previous;
1398 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1399 return tmp->next->Previous();
1409 // This function is able to hide closed footnotes.
1410 LyXParagraph const * LyXParagraph::Previous() const
1413 LyXParagraph * tmp = previous;
1417 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1418 tmp = tmp->previous;
1420 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1421 tmp = tmp->previous;
1422 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1423 return tmp->next->Previous();
1433 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1434 LyXParagraph::size_type pos,
1437 size_type i, j, pos_end, pos_first;
1438 // create a new paragraph
1439 LyXParagraph * par = ParFromPos(pos);
1441 LyXParagraph * firstpar = FirstPhysicalPar();
1443 LyXParagraph * firstpar = this;
1446 LyXParagraph * tmp = new LyXParagraph(par);
1449 tmp->footnoteflag = footnoteflag;
1450 tmp->footnotekind = footnotekind;
1452 // this is an idea for a more userfriendly layout handling, I will
1453 // see what the users say
1455 // layout stays the same with latex-environments
1457 tmp->SetOnlyLayout(bparams, firstpar->layout);
1458 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1461 if (Last() > pos || !Last() || flag == 2) {
1462 tmp->SetOnlyLayout(bparams, firstpar->layout);
1463 tmp->align = firstpar->align;
1464 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1466 tmp->line_bottom = firstpar->line_bottom;
1467 firstpar->line_bottom = false;
1468 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1469 firstpar->pagebreak_bottom = false;
1470 tmp->added_space_bottom = firstpar->added_space_bottom;
1471 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1473 tmp->depth = firstpar->depth;
1474 tmp->noindent = firstpar->noindent;
1476 // copy everything behind the break-position
1477 // to the new paragraph
1479 while (ParFromPos(pos_first) != par)
1482 pos_end = pos_first + par->text.size() - 1;
1484 for (i = j = pos; i <= pos_end; ++i) {
1485 par->CutIntoMinibuffer(bparams, i - pos_first);
1486 if (tmp->InsertFromMinibuffer(j - pos))
1489 tmp->text.resize(tmp->text.size());
1490 for (i = pos_end; i >= pos; --i)
1491 par->Erase(i - pos_first);
1493 par->text.resize(par->text.size());
1496 // just an idea of me
1498 tmp->line_top = firstpar->line_top;
1499 tmp->pagebreak_top = firstpar->pagebreak_top;
1500 tmp->added_space_top = firstpar->added_space_top;
1501 tmp->bibkey = firstpar->bibkey;
1503 // layout stays the same with latex-environments
1505 firstpar->SetOnlyLayout(bparams, tmp->layout);
1506 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1507 firstpar->depth = tmp->depth;
1513 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1516 par = par->FirstPhysicalPar();
1517 footnoteflag = par->footnoteflag;
1518 footnotekind = par->footnotekind;
1520 layout = par->layout;
1521 align = par-> align;
1522 SetLabelWidthString(par->labelwidthstring);
1524 line_bottom = par->line_bottom;
1525 pagebreak_bottom = par->pagebreak_bottom;
1526 added_space_bottom = par->added_space_bottom;
1528 line_top = par->line_top;
1529 pagebreak_top = par->pagebreak_top;
1530 added_space_top = par->added_space_top;
1532 spacing = par->spacing;
1534 pextra_type = par->pextra_type;
1535 pextra_width = par->pextra_width;
1536 pextra_widthp = par->pextra_widthp;
1537 pextra_alignment = par->pextra_alignment;
1538 pextra_hfill = par->pextra_hfill;
1539 pextra_start_minipage = par->pextra_start_minipage;
1541 noindent = par->noindent;
1547 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1549 LyXParagraph * tmppar = this;
1552 && tmppar->previous->footnoteflag ==
1553 LyXParagraph::CLOSED_FOOTNOTE)
1554 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1555 tmppar = tmppar->previous;
1558 return this; // This should never happen!
1565 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1567 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1577 && (IsNewline(0) || IsLineSeparator(0))){
1586 LyXParagraph * LyXParagraph::Clone() const
1588 // create a new paragraph
1589 LyXParagraph * result = new LyXParagraph;
1591 result->MakeSameLayout(this);
1593 // this is because of the dummy layout of the paragraphs that
1595 result->layout = layout;
1598 /* table stuff -- begin*/
1600 result->table = table->Clone();
1603 /* table stuff -- end*/
1605 result->inset_owner = inset_owner;
1608 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1611 // copy everything behind the break-position to the new paragraph
1613 result->text = text;
1614 result->fontlist = fontlist;
1615 result->insetlist = insetlist;
1616 for (InsetList::iterator it = result->insetlist.begin();
1617 it != result->insetlist.end(); ++it)
1618 (*it).inset = (*it).inset->Clone();
1623 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1626 par = par->FirstPhysicalPar();
1631 par->footnoteflag == footnoteflag &&
1632 par->footnotekind == footnotekind &&
1634 par->layout == layout &&
1636 par->align == align &&
1638 par->line_bottom == line_bottom &&
1639 par->pagebreak_bottom == pagebreak_bottom &&
1640 par->added_space_bottom == added_space_bottom &&
1642 par->line_top == line_top &&
1643 par->pagebreak_top == pagebreak_top &&
1644 par->added_space_top == added_space_top &&
1646 par->spacing == spacing &&
1648 par->pextra_type == pextra_type &&
1649 par->pextra_width == pextra_width &&
1650 par->pextra_widthp == pextra_widthp &&
1651 par->pextra_alignment == pextra_alignment &&
1652 par->pextra_hfill == pextra_hfill &&
1653 par->pextra_start_minipage == pextra_start_minipage &&
1655 par->table == table && // what means: NO TABLE AT ALL
1658 par->noindent == noindent &&
1659 par->depth == depth);
1663 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1664 LyXParagraph::size_type pos)
1666 // create a new paragraph
1667 LyXParagraph * par = ParFromPos(pos);
1669 LyXParagraph * tmp = new LyXParagraph(par);
1671 tmp->MakeSameLayout(par);
1673 // When can pos < Last()?
1674 // I guess pos == Last() is possible.
1676 // copy everything behind the break-position to the new
1678 size_type pos_first = 0;
1679 while (ParFromPos(pos_first) != par)
1681 size_type pos_end = pos_first + par->text.size() - 1;
1684 for (i = j = pos; i <= pos_end; ++i) {
1685 par->CutIntoMinibuffer(bparams, i - pos_first);
1686 if (tmp->InsertFromMinibuffer(j - pos))
1689 tmp->text.resize(tmp->text.size());
1690 for (size_type i = pos_end; i >= pos; --i)
1691 par->Erase(i - pos_first);
1693 par->text.resize(par->text.size());
1698 // Be carefull, this does not make any check at all.
1699 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1701 // copy the next paragraph to this one
1702 LyXParagraph * the_next = Next();
1704 LyXParagraph * firstpar = FirstPhysicalPar();
1706 LyXParagraph * firstpar = this;
1709 // first the DTP-stuff
1710 firstpar->line_bottom = the_next->line_bottom;
1711 firstpar->added_space_bottom = the_next->added_space_bottom;
1712 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1714 size_type pos_end = the_next->text.size() - 1;
1715 size_type pos_insert = Last();
1717 // ok, now copy the paragraph
1719 for (i = j = 0; i <= pos_end; ++i) {
1720 the_next->CutIntoMinibuffer(bparams, i);
1721 if (InsertFromMinibuffer(pos_insert + j))
1725 // delete the next paragraph
1726 LyXParagraph * ppar = the_next->previous;
1727 LyXParagraph * npar = the_next->next;
1734 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1736 LyXParagraph * par = ParFromPos(pos);
1738 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1739 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1745 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1747 LyXParagraph * par = ParFromPos(pos);
1749 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1750 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1757 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1759 LyXParagraph const * par = this;
1760 int par_depth = GetDepth();
1762 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1764 textclasslist.Style(bparams.textclass,
1765 layout).endlabeltype;
1766 if (endlabeltype != END_LABEL_NO_LABEL) {
1767 LyXParagraph const * last = this;
1769 if( footnoteflag == NO_FOOTNOTE)
1770 last = LastPhysicalPar();
1771 else if (next->footnoteflag == NO_FOOTNOTE)
1772 return endlabeltype;
1777 if (!last || !last->next)
1778 return endlabeltype;
1780 int next_depth = last->next->GetDepth();
1781 if (par_depth > next_depth ||
1782 (par_depth == next_depth && layout != last->next->GetLayout() ))
1783 return endlabeltype;
1788 par = par->DepthHook(par_depth - 1);
1790 par_depth = par->GetDepth();
1792 return END_LABEL_NO_LABEL;
1796 LyXTextClass::size_type LyXParagraph::GetLayout() const
1799 return FirstPhysicalPar()->layout;
1806 char LyXParagraph::GetDepth() const
1809 return FirstPhysicalPar()->depth;
1816 char LyXParagraph::GetAlign() const
1819 return FirstPhysicalPar()->align;
1826 string const & LyXParagraph::GetLabelstring() const
1829 return FirstPhysicalPar()->labelstring;
1836 int LyXParagraph::GetFirstCounter(int i) const
1839 return FirstPhysicalPar()->counter_[i];
1846 // the next two functions are for the manual labels
1847 string LyXParagraph::GetLabelWidthString() const
1850 if (!FirstPhysicalPar()->labelwidthstring.empty())
1851 return FirstPhysicalPar()->labelwidthstring;
1853 if (!labelwidthstring.empty())
1854 return labelwidthstring;
1857 return _("Senseless with this layout!");
1861 void LyXParagraph::SetLabelWidthString(string const & s)
1864 LyXParagraph * par = FirstPhysicalPar();
1866 par->labelwidthstring = s;
1868 labelwidthstring = s;
1873 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1874 LyXTextClass::size_type new_layout)
1877 LyXParagraph * par = FirstPhysicalPar();
1879 LyXParagraph * par = this;
1881 LyXParagraph * ppar = 0;
1882 LyXParagraph * npar = 0;
1884 par->layout = new_layout;
1886 /* table stuff -- begin*/
1889 /* table stuff -- end*/
1891 if (par->pextra_type == PEXTRA_NONE) {
1892 if (par->Previous()) {
1894 ppar = par->Previous()->FirstPhysicalPar();
1896 ppar = par->Previous();
1900 && (ppar->depth > par->depth))
1902 ppar = ppar->Previous()->FirstPhysicalPar();
1904 ppar = ppar->Previous();
1909 npar = par->Next()->NextAfterFootnote();
1915 && (npar->depth > par->depth))
1917 npar = npar->Next()->NextAfterFootnote();
1919 npar = npar->Next();
1922 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1924 p1 = ppar->pextra_width,
1925 p2 = ppar->pextra_widthp;
1926 ppar->SetPExtraType(bparams, ppar->pextra_type,
1927 p1.c_str(), p2.c_str());
1929 if ((par->pextra_type == PEXTRA_NONE) &&
1930 npar && (npar->pextra_type != PEXTRA_NONE)) {
1932 p1 = npar->pextra_width,
1933 p2 = npar->pextra_widthp;
1934 npar->SetPExtraType(bparams, npar->pextra_type,
1935 p1.c_str(), p2.c_str());
1941 void LyXParagraph::SetLayout(BufferParams const & bparams,
1942 LyXTextClass::size_type new_layout)
1946 * par = FirstPhysicalPar(),
1953 par->layout = new_layout;
1954 par->labelwidthstring.erase();
1955 par->align = LYX_ALIGN_LAYOUT;
1956 par->added_space_top = VSpace(VSpace::NONE);
1957 par->added_space_bottom = VSpace(VSpace::NONE);
1958 par->spacing.set(Spacing::Default);
1961 /* table stuff -- begin*/
1964 /* table stuff -- end*/
1966 if (par->pextra_type == PEXTRA_NONE) {
1967 if (par->Previous()) {
1969 ppar = par->Previous()->FirstPhysicalPar();
1971 ppar = par->Previous();
1975 && (ppar->depth > par->depth))
1977 ppar = ppar->Previous()->FirstPhysicalPar();
1979 ppar = ppar->Previous();
1984 npar = par->Next()->NextAfterFootnote();
1990 && (npar->depth > par->depth))
1992 npar = npar->Next()->NextAfterFootnote();
1994 npar = npar->Next();
1997 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1999 p1 = ppar->pextra_width,
2000 p2 = ppar->pextra_widthp;
2001 ppar->SetPExtraType(bparams, ppar->pextra_type,
2002 p1.c_str(), p2.c_str());
2004 if ((par->pextra_type == PEXTRA_NONE) &&
2005 npar && (npar->pextra_type != PEXTRA_NONE)) {
2007 p1 = npar->pextra_width,
2008 p2 = npar->pextra_widthp;
2009 npar->SetPExtraType(bparams, npar->pextra_type,
2010 p1.c_str(), p2.c_str());
2016 // if the layout of a paragraph contains a manual label, the beginning of the
2017 // main body is the beginning of the second word. This is what the par-
2018 // function returns. If the layout does not contain a label, the main
2019 // body always starts with position 0. This differentiation is necessary,
2020 // because there cannot be a newline or a blank <= the beginning of the
2021 // main body in TeX.
2023 int LyXParagraph::BeginningOfMainBody() const
2026 if (FirstPhysicalPar() != this)
2029 // Unroll the first two cycles of the loop
2030 // and remember the previous character to
2031 // remove unnecessary GetChar() calls
2034 && GetChar(i) != LyXParagraph::META_NEWLINE
2037 char previous_char = 0, temp = 0;
2039 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2040 // Yes, this ^ is supposed to be "= " not "=="
2043 && previous_char != ' '
2044 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2046 previous_char = temp;
2052 if (i == 0 && i == size() &&
2053 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2054 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2055 ++i; /* the cursor should not jump
2056 * to the main body if there
2063 LyXParagraph * LyXParagraph::DepthHook(int deth)
2065 LyXParagraph * newpar = this;
2071 newpar = newpar->FirstPhysicalPar()->Previous();
2073 newpar = newpar->Previous();
2075 } while (newpar && newpar->GetDepth() > deth
2077 && newpar->footnoteflag == footnoteflag
2082 if (Previous() || GetDepth())
2083 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2088 return newpar->FirstPhysicalPar();
2095 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2097 LyXParagraph const * newpar = this;
2103 newpar = newpar->FirstPhysicalPar()->Previous();
2105 newpar = newpar->Previous();
2107 } while (newpar && newpar->GetDepth() > deth
2109 && newpar->footnoteflag == footnoteflag
2114 if (Previous() || GetDepth())
2115 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2120 return newpar->FirstPhysicalPar();
2127 int LyXParagraph::AutoDeleteInsets()
2130 InsetList::size_type index = 0;
2131 while (index < insetlist.size()) {
2132 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2133 Erase(insetlist[index].pos);
2134 // Erase() calls to insetlist.erase(&insetlist[index])
2135 // so index shouldn't be increased.
2144 LyXParagraph::inset_iterator
2145 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2147 InsetTable search_inset(pos, 0);
2148 InsetList::iterator it = lower_bound(insetlist.begin(),
2150 search_inset, matchIT());
2151 return inset_iterator(it);
2155 // returns -1 if inset not found
2156 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2159 // We could use lower_bound here too, we just need to add
2160 // the approp. operator() to matchIT (and change the name
2161 // of that struct). Code would then be:
2162 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2164 // inset, matchIT());
2165 // if ((*cit).inset == inset) {
2166 // return (*cit).pos;
2168 for (InsetList::const_iterator cit = insetlist.begin();
2169 cit != insetlist.end(); ++cit) {
2170 if ((*cit).inset == inset) {
2175 // Think about footnotes.
2176 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2177 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2179 NextAfterFootnote()->GetPositionOfInset(inset);
2181 return text.size() + 1 + further;
2188 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2189 BufferParams const & bparams,
2190 ostream & os, TexRow & texrow,
2195 TexRow & foot_texrow,
2200 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2201 LyXLayout const & style =
2202 textclasslist.Style(bparams.textclass,
2205 bool further_blank_line = false;
2208 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2211 if (start_of_appendix) {
2212 os << "\\appendix\n";
2216 if (!spacing.isDefault()
2217 && (!Previous() || !Previous()->HasSameLayout(this))) {
2218 os << spacing.writeEnvirBegin() << "\n";
2222 if (tex_code_break_column && style.isCommand()){
2227 if (pagebreak_top) {
2229 further_blank_line = true;
2231 if (added_space_top.kind() != VSpace::NONE) {
2232 os << added_space_top.asLatexCommand(bparams);
2233 further_blank_line = true;
2237 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2238 << "\\vspace{-1\\parskip}";
2239 further_blank_line = true;
2242 if (further_blank_line){
2247 Language const * language = getParLanguage(bparams);
2248 Language const * doc_language = bparams.language_info;
2249 Language const * previous_language = previous
2250 ? previous->getParLanguage(bparams) : doc_language;
2251 if (language != doc_language && language != previous_language) {
2252 os << subst(lyxrc.language_command_begin, "$$lang",
2258 if (bparams.inputenc == "auto" &&
2259 language->encoding() != previous_language->encoding()) {
2260 os << "\\inputencoding{"
2261 << language->encoding()->LatexName()
2266 switch (style.latextype) {
2269 << style.latexname()
2270 << style.latexparam();
2272 case LATEX_ITEM_ENVIRONMENT:
2274 bibkey->Latex(buf, os, false, false);
2278 case LATEX_LIST_ENVIRONMENT:
2285 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2287 LyXParagraph * par = next;
2289 // Spit out footnotes
2290 if (lyxrc.rtl_support) {
2291 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2292 && next->footnoteflag != footnoteflag) {
2293 LyXParagraph * p = 0;
2294 bool is_rtl = (size() > 0)
2295 ? GetFontSettings(bparams,
2296 size()-1).isRightToLeft()
2297 : language->RightToLeft();
2298 if ( (p = NextAfterFootnote()) != 0 &&
2300 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2301 is_rtl = getParLanguage(bparams)->RightToLeft();
2302 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2303 && par->footnoteflag != footnoteflag) {
2304 par = par->TeXFootnote(buf, bparams,
2306 foot_texrow, foot_count,
2308 par->SimpleTeXOnePar(buf, bparams,
2309 os, texrow, moving_arg);
2310 is_rtl = (par->size() > 0)
2311 ? par->GetFontSettings(bparams,
2312 par->size()-1).isRightToLeft()
2313 : language->RightToLeft();
2315 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2316 (p = par->NextAfterFootnote()) != 0 &&
2318 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2319 is_rtl = language->RightToLeft();
2324 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2325 && par->footnoteflag != footnoteflag) {
2326 par = par->TeXFootnote(buf, bparams,
2328 foot, foot_texrow, foot_count,
2330 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2336 // Make sure that \\par is done with the font of the last
2337 // character if this has another size as the default.
2338 // This is necessary because LaTeX (and LyX on the screen)
2339 // calculates the space between the baselines according
2340 // to this font. (Matthias)
2341 LyXFont font = getFont(bparams, Last() - 1);
2343 if (style.resfont.size() != font.size()) {
2349 } else if (textclasslist.Style(bparams.textclass,
2350 GetLayout()).isCommand()) {
2351 if (style.resfont.size() != font.size()) {
2357 } else if (style.resfont.size() != font.size()){
2358 os << "{\\" << font.latexSize() << " \\par}";
2361 if (language != doc_language &&
2364 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2366 || par->getParLanguage(bparams) != language)) {
2368 << subst(lyxrc.language_command_end, "$$lang",
2369 doc_language->lang());
2372 switch (style.latextype) {
2373 case LATEX_ITEM_ENVIRONMENT:
2374 case LATEX_LIST_ENVIRONMENT:
2375 if (par && (depth < par->depth)) {
2380 case LATEX_ENVIRONMENT:
2381 // if its the last paragraph of the current environment
2382 // skip it otherwise fall through
2384 && (par->layout != layout
2385 || par->depth != depth
2386 || par->pextra_type != pextra_type))
2389 // we don't need it for the last paragraph!!!
2393 footnoteflag != LyXParagraph::NO_FOOTNOTE
2394 && footnotekind != LyXParagraph::FOOTNOTE
2395 && footnotekind != LyXParagraph::MARGIN &&
2400 // don't insert this if we would be adding it
2401 // before or after a table in a float. This
2402 // little trick is needed in order to allow
2403 // use of tables in \subfigures or \subtables.
2409 further_blank_line = false;
2411 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2412 further_blank_line = true;
2415 if (added_space_bottom.kind() != VSpace::NONE) {
2416 os << added_space_bottom.asLatexCommand(bparams);
2417 further_blank_line = true;
2420 if (pagebreak_bottom) {
2422 further_blank_line = true;
2425 if (further_blank_line){
2430 if (!spacing.isDefault()
2431 && (!par || !par->HasSameLayout(this))) {
2432 os << spacing.writeEnvirEnd() << "\n";
2436 // we don't need it for the last paragraph!!!
2439 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2440 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2447 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2452 // This one spits out the text of the paragraph
2453 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2454 BufferParams const & bparams,
2455 ostream & os, TexRow & texrow,
2458 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2462 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2465 bool return_value = false;
2467 LyXLayout const & style =
2468 textclasslist.Style(bparams.textclass,
2470 LyXFont basefont, last_font;
2472 // Maybe we have to create a optional argument.
2473 size_type main_body;
2474 if (style.labeltype != LABEL_MANUAL)
2477 main_body = BeginningOfMainBody();
2479 if (main_body > 0) {
2481 basefont = getFont(bparams, -2); // Get label font
2483 basefont = getFont(bparams, -1); // Get layout font
2494 if (style.isCommand()) {
2497 } else if (align != LYX_ALIGN_LAYOUT) {
2500 return_value = true;
2504 moving_arg |= style.needprotect;
2506 // Which font is currently active?
2507 LyXFont running_font(basefont);
2508 // Do we have an open font change?
2509 bool open_font = false;
2511 texrow.start(this, 0);
2513 for (size_type i = 0; i < size(); ++i) {
2515 // First char in paragraph or after label?
2521 if (main_body > 0) {
2523 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2526 basefont = getFont(bparams, -1); // Now use the layout font
2527 running_font = basefont;
2531 if (style.isCommand()) {
2534 } else if (align != LYX_ALIGN_LAYOUT) {
2537 return_value = true;
2541 os << "\\noindent ";
2545 case LYX_ALIGN_NONE:
2546 case LYX_ALIGN_BLOCK:
2547 case LYX_ALIGN_LAYOUT:
2548 case LYX_ALIGN_SPECIAL:
2550 case LYX_ALIGN_LEFT:
2551 if (getParLanguage(bparams)->lang() != "hebrew") {
2552 os << "\\raggedright ";
2555 os << "\\raggedleft ";
2559 case LYX_ALIGN_RIGHT:
2560 if (getParLanguage(bparams)->lang() != "hebrew") {
2561 os << "\\raggedleft ";
2564 os << "\\raggedright ";
2568 case LYX_ALIGN_CENTER:
2569 os << "\\centering ";
2575 value_type c = GetChar(i);
2577 // Fully instantiated font
2578 LyXFont font = getFont(bparams, i);
2579 LyXParagraph * p = 0;
2583 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2584 (p = PreviousBeforeFootnote()) != 0)
2588 last_font = p->getFont(bparams, p->size() - 1);
2590 last_font = running_font;
2592 // Spaces at end of font change are simulated to be
2593 // outside font change, i.e. we write "\textXX{text} "
2594 // rather than "\textXX{text }". (Asger)
2595 if (open_font && c == ' ' && i <= size() - 2
2596 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2597 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2598 font = getFont(bparams, i + 1);
2600 // We end font definition before blanks
2601 if (!font.equalExceptLatex(running_font) && open_font) {
2602 column += running_font.latexWriteEndChanges(os,
2604 (i == main_body-1) ? basefont : font);
2605 running_font = basefont;
2609 // Blanks are printed before start of fontswitch
2611 // Do not print the separation of the optional argument
2612 if (i != main_body - 1) {
2613 SimpleTeXBlanks(os, texrow, i,
2614 column, font, style);
2618 // Do we need to change font?
2619 if (!font.equalExceptLatex(running_font)
2620 && i != main_body-1) {
2621 column += font.latexWriteStartChanges(os, basefont,
2623 running_font = font;
2627 if (c == LyXParagraph::META_NEWLINE) {
2628 // newlines are handled differently here than
2629 // the default in SimpleTeXSpecialChars().
2630 if (!style.newline_allowed
2631 || font.latex() == LyXFont::ON) {
2635 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2638 basefont = getFont(bparams, -1);
2639 running_font = basefont;
2640 if (font.family() ==
2641 LyXFont::TYPEWRITER_FAMILY) {
2649 texrow.start(this, i + 1);
2652 SimpleTeXSpecialChars(buf, bparams,
2653 os, texrow, moving_arg,
2654 font, running_font, basefont,
2655 open_font, style, i, column, c);
2659 // If we have an open font definition, we have to close it
2661 LyXParagraph * p = 0;
2664 && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2665 && (p = NextAfterFootnote()) != 0
2670 running_font.latexWriteEndChanges(os, basefont,
2671 p->getFont(bparams, 0));
2673 running_font.latexWriteEndChanges(os, basefont, basefont);
2676 // Needed if there is an optional argument but no contents.
2677 if (main_body > 0 && main_body == size()) {
2679 return_value = false;
2682 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2683 return return_value;
2687 // This one spits out the text of a table paragraph
2688 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2689 BufferParams const & bparams,
2690 ostream & os, TexRow & texrow)
2692 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2694 bool return_value = false;
2696 LyXLayout const & style =
2697 textclasslist.Style(bparams.textclass, GetLayout());
2701 if (!IsDummy()) { // it is dummy if it is in a float!!!
2703 if (style.isCommand()) {
2706 } else if (align != LYX_ALIGN_LAYOUT) {
2709 return_value = true;
2712 os << "\\noindent ";
2716 case LYX_ALIGN_NONE:
2717 case LYX_ALIGN_BLOCK:
2718 case LYX_ALIGN_LAYOUT:
2719 case LYX_ALIGN_SPECIAL: break;
2720 case LYX_ALIGN_LEFT:
2721 os << "\\raggedright ";
2724 case LYX_ALIGN_RIGHT:
2725 os << "\\raggedleft ";
2728 case LYX_ALIGN_CENTER:
2729 os << "\\centering ";
2737 LyXFont basefont = getFont(bparams, -1); // Get layout font
2738 // Which font is currently active?
2739 LyXFont running_font = basefont;
2741 // Do we have an open font change?
2742 bool open_font = false;
2743 int current_cell_number = -1;
2744 int tmp = table->TexEndOfCell(os, current_cell_number);
2745 for (; tmp > 0 ; --tmp)
2748 texrow.start(this, 0);
2750 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2751 bool first_in_cell = true;
2753 for (size_type i = 0; i < size(); ++i) {
2754 value_type c = GetChar(i);
2755 if (table->IsContRow(current_cell_number + 1)) {
2756 if (c == LyXParagraph::META_NEWLINE)
2757 ++current_cell_number;
2762 if (first_in_cell && is_rtl) {
2765 first_in_cell = false;
2768 // Fully instantiated font
2769 LyXFont font = getFont(bparams, i);
2770 last_font = running_font;
2772 // Spaces at end of font change are simulated to be
2773 // outside font change.
2774 // i.e. we write "\textXX{text} " rather than
2775 // "\textXX{text }". (Asger)
2776 if (open_font && c == ' ' && i <= size() - 2
2777 && getFont(bparams, i + 1) != running_font
2778 && getFont(bparams, i + 1) != font) {
2779 font = getFont(bparams, i + 1);
2782 // We end font definition before blanks
2783 if (font != running_font && open_font) {
2784 column += running_font.latexWriteEndChanges(os,
2787 running_font = basefont;
2790 // Blanks are printed before start of fontswitch
2792 SimpleTeXBlanks(os, texrow, i, column, font, style);
2794 // Do we need to change font?
2795 if (font != running_font) {
2796 column += font.latexWriteStartChanges(os, basefont,
2798 running_font = font;
2801 // Do we need to turn on LaTeX mode?
2802 if (font.latex() != running_font.latex()) {
2803 if (font.latex() == LyXFont::ON
2804 && style.needprotect) {
2809 if (c == LyXParagraph::META_NEWLINE) {
2810 // special case for inside a table
2811 // different from default case in
2812 // SimpleTeXSpecialChars()
2814 column += running_font
2815 .latexWriteEndChanges(os, basefont,
2819 basefont = getFont(bparams, -1);
2820 running_font = basefont;
2821 ++current_cell_number;
2822 if (table->CellHasContRow(current_cell_number) >= 0) {
2823 TeXContTableRows(buf, bparams, os, i + 1,
2824 current_cell_number,
2827 if (is_rtl && !first_in_cell) {
2829 first_in_cell = true;
2832 // if this cell follow only ContRows till end don't
2833 // put the EndOfCell because it is put after the
2835 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2836 --current_cell_number;
2839 int tmp = table->TexEndOfCell(os,
2840 current_cell_number);
2843 } else if (tmp < 0) {
2849 texrow.start(this, i + 1);
2851 SimpleTeXSpecialChars(buf, bparams,
2853 font, running_font, basefont,
2854 open_font, style, i, column, c);
2858 // If we have an open font definition, we have to close it
2860 running_font.latexWriteEndChanges(os, basefont, basefont);
2862 ++current_cell_number;
2863 if (is_rtl && !first_in_cell)
2865 tmp = table->TexEndOfCell(os, current_cell_number);
2866 for (; tmp > 0; --tmp)
2868 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2869 return return_value;
2873 // This one spits out the text off ContRows in tables
2874 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2875 BufferParams const & bparams,
2877 LyXParagraph::size_type i,
2878 int current_cell_number,
2879 int & column, TexRow & texrow)
2881 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2885 bool return_value = false;
2886 LyXLayout const & style =
2887 textclasslist.Style(bparams.textclass,
2889 LyXFont basefont = getFont(bparams, -1); // Get layout font
2891 // Which font is currently active?
2892 LyXFont running_font = basefont;
2893 // Do we have an open font change?
2894 bool open_font = false;
2896 size_type lastpos = i;
2897 int cell = table->CellHasContRow(current_cell_number);
2898 ++current_cell_number;
2901 // first find the right position
2903 for (; (i < size()) && (current_cell_number < cell); ++i) {
2905 if (c == LyXParagraph::META_NEWLINE)
2906 ++current_cell_number;
2910 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2914 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2919 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2923 // Fully instantiated font
2924 LyXFont font = getFont(bparams, i);
2925 last_font = running_font;
2927 // Spaces at end of font change are simulated to
2928 // be outside font change. i.e. we write
2929 // "\textXX{text} " rather than "\textXX{text }".
2931 if (open_font && c == ' ' && i <= size() - 2
2932 && getFont(bparams, i + 1) != running_font
2933 && getFont(bparams, i + 1) != font) {
2934 font = getFont(bparams, i + 1);
2937 // We end font definition before blanks
2938 if (font != running_font && open_font) {
2939 column += running_font.latexWriteEndChanges(os, basefont, font);
2940 running_font = basefont;
2943 // Blanks are printed before start of fontswitch
2945 SimpleTeXBlanks(os, texrow, i,
2946 column, font, style);
2948 // Do we need to change font?
2949 if (font != running_font) {
2951 font.latexWriteStartChanges(os,
2954 running_font = font;
2957 // Do we need to turn on LaTeX mode?
2958 if (font.latex() != running_font.latex()) {
2959 if (font.latex() == LyXFont::ON
2960 && style.needprotect) {
2965 SimpleTeXSpecialChars(buf, bparams,
2966 os, texrow, false, font,
2967 running_font, basefont,
2968 open_font, style, i, column, c);
2970 // If we have an open font definition, we have to close it
2972 running_font.latexWriteEndChanges(os, basefont,
2976 basefont = getFont(bparams, -1);
2977 running_font = basefont;
2978 cell = table->CellHasContRow(current_cell_number);
2980 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2981 return return_value;
2985 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2987 bool retval = false;
2989 case LyXParagraph::META_HFILL:
2990 sgml_string.erase();
2992 case LyXParagraph::META_NEWLINE:
2996 sgml_string = "&";
2999 sgml_string = "<";
3002 sgml_string = ">";
3005 sgml_string = "$";
3008 sgml_string = "#";
3011 sgml_string = "%";
3014 sgml_string = "[";
3017 sgml_string = "]";
3020 sgml_string = "{";
3023 sgml_string = "}";
3026 sgml_string = "˜";
3029 sgml_string = """;
3032 sgml_string = "\";
3038 case '\0': // Ignore :-)
3039 sgml_string.erase();
3049 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
3050 ostream & os, string & extra,
3051 int & desc_on, int depth)
3053 BufferParams const & bparams = buffer->params;
3055 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
3057 LyXFont font1, font2;
3060 size_type main_body;
3061 bool emph_flag = false;
3063 LyXLayout const & style =
3064 textclasslist.Style(bparams.textclass,
3067 if (style.labeltype != LABEL_MANUAL)
3070 main_body = BeginningOfMainBody();
3072 // Gets paragraph main font.
3074 font1 = style.labelfont;
3078 int char_line_count = depth;
3079 os << newlineAndDepth(depth);
3081 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3082 os << "<INFORMALTABLE>"
3083 << newlineAndDepth(++depth);
3086 os << "<INFORMALTABLE>"
3087 << newlineAndDepth(++depth);
3089 int current_cell_number = -1;
3090 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3092 // Parsing main loop.
3093 for (size_type i = 0; i < size(); ++i) {
3095 if (table->IsContRow(current_cell_number+1)) {
3096 if (c == LyXParagraph::META_NEWLINE)
3097 ++current_cell_number;
3102 // Fully instantiated font
3103 font2 = getFont(bparams, i);
3105 // Handle <emphasis> tag.
3106 if (font1.emph() != font2.emph() && i) {
3107 if (font2.emph() == LyXFont::ON) {
3110 } else if (emph_flag) {
3111 os << "</emphasis>";
3115 if (c == LyXParagraph::META_NEWLINE) {
3116 // We have only to control for emphasis open here!
3118 os << "</emphasis>";
3121 font1 = font2 = getFont(bparams, -1);
3122 ++current_cell_number;
3123 if (table->CellHasContRow(current_cell_number) >= 0) {
3124 DocBookContTableRows(buffer,
3125 os, extra, desc_on, i + 1,
3126 current_cell_number,
3129 // if this cell follow only ContRows till end don't
3130 // put the EndOfCell because it is put after the
3132 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3133 --current_cell_number;
3136 tmp = table->DocBookEndOfCell(os,
3137 current_cell_number,
3142 } else if (c == LyXParagraph::META_INSET) {
3143 inset = GetInset(i);
3145 std::ostringstream ost;
3146 inset->DocBook(buffer, ost);
3147 string tmp_out = ost.str().c_str();
3150 inset->DocBook(buffer, ost);
3152 char * ctmp = ost.str();
3153 string tmp_out(ctmp);
3157 // This code needs some explanation:
3158 // Two insets are treated specially
3159 // label if it is the first element in a
3160 // command paragraph
3162 // graphics inside tables or figure floats
3164 // title (the equivalente in latex for this
3166 // and title should come first
3169 if(desc_on != 3 || i != 0) {
3170 if(tmp_out[0] == '@') {
3172 extra += frontStrip(tmp_out,
3175 os << frontStrip(tmp_out,
3180 } else if (font2.latex() == LyXFont::ON) {
3181 // "TeX"-Mode on == > SGML-Mode on.
3187 if (linuxDocConvertChar(c, sgml_string)
3188 && !style.free_spacing) {
3189 // in freespacing mode, spaces are
3190 // non-breaking characters
3195 << "</term><listitem><para>";
3207 // Needed if there is an optional argument but no contents.
3208 if (main_body > 0 && main_body == size()) {
3213 os << "</emphasis>";
3216 ++current_cell_number;
3217 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3218 // Resets description flag correctly.
3221 // <term> not closed...
3226 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3228 os << "</INFORMALTABLE>";
3230 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3235 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3236 ostream & os, string & extra,
3238 LyXParagraph::size_type i,
3239 int current_cell_number, int &column)
3244 BufferParams const & bparams = buffer->params;
3246 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3251 //string emph = "emphasis";
3252 bool emph_flag = false;
3253 int char_line_count = 0;
3255 LyXLayout const & style =
3256 textclasslist.Style(bparams.textclass,
3259 size_type main_body;
3260 if (style.labeltype != LABEL_MANUAL)
3263 main_body = BeginningOfMainBody();
3265 // Gets paragraph main font.
3268 font1 = style.labelfont;
3272 size_type lastpos = i;
3273 int cell = table->CellHasContRow(current_cell_number);
3274 ++current_cell_number;
3276 // first find the right position
3278 for (; i < size() && current_cell_number < cell; ++i) {
3280 if (c == LyXParagraph::META_NEWLINE)
3281 ++current_cell_number;
3285 // I don't know how to handle this so I comment it
3286 // for the moment (Jug)
3287 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3288 // file += " \\\\\n";
3291 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3296 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3300 // Fully instantiated font
3301 font2 = getFont(bparams, i);
3303 // Handle <emphasis> tag.
3304 if (font1.emph() != font2.emph() && i) {
3305 if (font2.emph() == LyXFont::ON) {
3308 } else if (emph_flag) {
3309 os << "</emphasis>";
3313 if (c == LyXParagraph::META_INSET) {
3314 inset = GetInset(i);
3316 std::ostringstream ost;
3317 inset->DocBook(buffer, ost);
3318 string tmp_out = ost.str().c_str();
3321 inset->DocBook(buffer, ost);
3323 char * ctmp = ost.str();
3324 string tmp_out(ctmp);
3328 // This code needs some explanation:
3329 // Two insets are treated specially
3330 // label if it is the first element in a
3331 // command paragraph
3333 // graphics inside tables or figure floats
3334 // can't go on title (the equivalente in
3335 // latex for this case is caption and title
3336 // should come first
3339 if(desc_on != 3 || i != 0) {
3340 if(tmp_out[0] == '@') {
3342 extra += frontStrip(tmp_out, '@');
3344 os << frontStrip(tmp_out, '@');
3348 } else if (font2.latex() == LyXFont::ON) {
3349 // "TeX"-Mode on == > SGML-Mode on.
3355 if (linuxDocConvertChar(c, sgml_string)
3356 && !style.free_spacing) {
3357 // in freespacing mode, spaces are
3358 // non-breaking characters
3363 << "</term><listitem><para>";
3373 // we have only to control for emphasis open here!
3375 os << "</emphasis>";
3378 font1 = font2 = getFont(bparams, -1);
3379 cell = table->CellHasContRow(current_cell_number);
3381 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3385 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3386 LyXParagraph::size_type const i,
3387 int & column, LyXFont const & font,
3388 LyXLayout const & style)
3390 if (column > tex_code_break_column
3392 && GetChar(i - 1) != ' '
3394 // In LaTeX mode, we don't want to
3395 // break lines since some commands
3397 && ! (font.latex() == LyXFont::ON)
3398 // same in FreeSpacing mode
3399 && !style.free_spacing
3400 // In typewriter mode, we want to avoid
3401 // ! . ? : at the end of a line
3402 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3403 && (GetChar(i-1) == '.'
3404 || GetChar(i-1) == '?'
3405 || GetChar(i-1) == ':'
3406 || GetChar(i-1) == '!'))) {
3407 if (tex_code_break_column == 0) {
3408 // in batchmode we need LaTeX to still
3409 // see it as a space not as an extra '\n'
3415 texrow.start(this, i + 1);
3417 } else if (font.latex() == LyXFont::OFF) {
3418 if (style.free_spacing) {
3427 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3428 BufferParams const & bparams,
3429 ostream & os, TexRow & texrow,
3432 LyXFont & running_font,
3435 LyXLayout const & style,
3436 LyXParagraph::size_type & i,
3438 LyXParagraph::value_type const c)
3440 // Two major modes: LaTeX or plain
3441 // Handle here those cases common to both modes
3442 // and then split to handle the two modes separately.
3444 case LyXParagraph::META_INSET: {
3445 Inset * inset = GetInset(i);
3448 int len = os.tellp();
3449 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3450 || inset->LyxCode() == Inset::MATH_CODE
3451 || inset->LyxCode() == Inset::URL_CODE)
3452 && running_font.isRightToLeft()) {
3457 int tmp = inset->Latex(buf, os, moving_arg,
3458 style.free_spacing);
3466 column += os.tellp() - len;
3475 case LyXParagraph::META_NEWLINE:
3477 column += running_font.latexWriteEndChanges(os,
3482 basefont = getFont(bparams, -1);
3483 running_font = basefont;
3486 case LyXParagraph::META_HFILL:
3492 // And now for the special cases within each mode
3493 // Are we in LaTeX mode?
3494 if (font.latex() == LyXFont::ON) {
3495 // at present we only have one option
3496 // but I'll leave it as a switch statement
3497 // so its simpler to extend. (ARRae)
3500 // make sure that we will not print
3501 // error generating chars to the tex
3502 // file. This test would not be needed
3503 // if it were done in the buffer
3511 // Plain mode (i.e. not LaTeX)
3514 os << "\\textbackslash{}";
3518 case '°': case '±': case '²': case '³':
3519 case '×': case '÷': case '¹': case 'ª':
3520 case 'º': case '¬': case 'µ':
3521 if (bparams.inputenc == "latin1" ||
3522 (bparams.inputenc == "auto" &&
3523 font.language()->encoding()->LatexName()
3525 os << "\\ensuremath{"
3534 case '|': case '<': case '>':
3535 // In T1 encoding, these characters exist
3536 if (lyxrc.fontenc == "T1") {
3538 //... but we should avoid ligatures
3539 if ((c == '>' || c == '<')
3541 && GetChar(i + 1) == c) {
3542 //os << "\\textcompwordmark{}";
3543 // Jean-Marc, have a look at
3544 // this. IÂ think this works
3552 // Typewriter font also has them
3553 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3557 // Otherwise, we use what LaTeX
3561 os << "\\textless{}";
3565 os << "\\textgreater{}";
3569 os << "\\textbar{}";
3575 case '-': // "--" in Typewriter mode -> "-{}-"
3577 && GetChar(i + 1) == '-'
3578 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3587 os << "\\char`\\\"{}";
3592 if (bparams.inputenc == "default") {
3601 case '%': case '#': case '{':
3608 os << "\\textasciitilde{}";
3613 os << "\\textasciicircum{}";
3617 case '*': case '[': case ']':
3618 // avoid being mistaken for optional arguments
3619 os << '{' << c << '}';
3624 // Blanks are printed before font switching.
3625 // Sure? I am not! (try nice-latex)
3626 // I am sure it's correct. LyX might be smarter
3627 // in the future, but for now, nothing wrong is
3632 /* idea for labels --- begin*/
3636 && font.family() != LyXFont::TYPEWRITER_FAMILY
3637 && GetChar(i + 1) == 'y'
3638 && GetChar(i + 2) == 'X') {
3646 && font.family() != LyXFont::TYPEWRITER_FAMILY
3647 && GetChar(i + 1) == 'e'
3648 && GetChar(i + 2) == 'X') {
3653 // Check for "LaTeX2e"
3656 && font.family() != LyXFont::TYPEWRITER_FAMILY
3657 && GetChar(i + 1) == 'a'
3658 && GetChar(i + 2) == 'T'
3659 && GetChar(i + 3) == 'e'
3660 && GetChar(i + 4) == 'X'
3661 && GetChar(i + 5) == '2'
3662 && GetChar(i + 6) == 'e') {
3667 // Check for "LaTeX"
3670 && font.family() != LyXFont::TYPEWRITER_FAMILY
3671 && GetChar(i + 1) == 'a'
3672 && GetChar(i + 2) == 'T'
3673 && GetChar(i + 3) == 'e'
3674 && GetChar(i + 4) == 'X') {
3678 /* idea for labels --- end*/
3679 } else if (c != '\0') {
3689 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3690 BufferParams const & bparams,
3691 ostream & os, TexRow & texrow,
3693 TexRow & foot_texrow,
3696 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3697 LyXParagraph * par = this;
3700 (par->depth == depth)
3702 && (par->footnoteflag == footnoteflag)
3707 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3709 if (textclasslist.Style(bparams.textclass,
3710 par->layout).isEnvironment()
3711 || par->pextra_type != PEXTRA_NONE) {
3712 par = par->TeXEnvironment(buf, bparams,
3717 par = par->TeXOnePar(buf, bparams,
3727 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3733 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3734 BufferParams const & bparams,
3735 ostream & os, TexRow & texrow,
3737 TexRow & foot_texrow,
3740 bool eindent_open = false;
3741 bool foot_this_level = false;
3742 // flags when footnotetext should be appended to file.
3743 static bool minipage_open = false;
3744 static int minipage_open_depth = 0;
3745 char par_sep = bparams.paragraph_separation;
3747 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3750 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3753 LyXLayout const & style =
3754 textclasslist.Style(bparams.textclass,
3757 if (pextra_type == PEXTRA_INDENT) {
3758 if (!pextra_width.empty()) {
3759 os << "\\begin{LyXParagraphIndent}{"
3760 << pextra_width << "}\n";
3762 //float ib = atof(pextra_widthp.c_str())/100;
3763 // string can't handle floats at present (971109)
3764 // so I'll do a conversion by hand knowing that
3765 // the limits are 0.0 to 1.0. ARRae.
3766 os << "\\begin{LyXParagraphIndent}{";
3767 switch (pextra_widthp.length()) {
3779 os << "\\columnwidth}\n";
3782 eindent_open = true;
3784 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3785 if (pextra_hfill && Previous() &&
3786 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3787 os << "\\hfill{}\n";
3790 if (par_sep == BufferParams::PARSEP_INDENT) {
3791 os << "{\\setlength\\parindent{0pt}\n";
3794 os << "\\begin{minipage}";
3795 switch(pextra_alignment) {
3796 case MINIPAGE_ALIGN_TOP:
3799 case MINIPAGE_ALIGN_MIDDLE:
3802 case MINIPAGE_ALIGN_BOTTOM:
3806 if (!pextra_width.empty()) {
3807 os << '{' << pextra_width << "}\n";
3809 //float ib = atof(par->pextra_width.c_str())/100;
3810 // string can't handle floats at present
3811 // so I'll do a conversion by hand knowing that
3812 // the limits are 0.0 to 1.0. ARRae.
3814 switch (pextra_widthp.length()) {
3826 os << "\\columnwidth}\n";
3829 if (par_sep == BufferParams::PARSEP_INDENT) {
3830 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3833 minipage_open = true;
3834 minipage_open_depth = depth;
3837 #ifdef WITH_WARNINGS
3838 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3839 //I disabled it because it breaks when lists span on several
3842 if (style.isEnvironment()){
3843 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3844 #ifdef FANCY_FOOTNOTE_CODE
3845 if (foot_count < 0) {
3846 // flag that footnote[mark][text] should be
3847 // used for any footnotes from now on
3849 foot_this_level = true;
3852 os << "\\begin{" << style.latexname() << "}{"
3853 << labelwidthstring << "}\n";
3854 } else if (style.labeltype == LABEL_BIBLIO) {
3856 os << "\\begin{" << style.latexname() << "}{"
3857 << bibitemWidest(current_view)
3859 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3860 #ifdef FANCY_FOOTNOTE_CODE
3861 if (foot_count < 0) {
3862 // flag that footnote[mark][text] should be
3863 // used for any footnotes from now on
3865 foot_this_level = true;
3868 os << "\\begin{" << style.latexname() << '}'
3869 << style.latexparam() << '\n';
3871 os << "\\begin{" << style.latexname() << '}'
3872 << style.latexparam() << '\n';
3875 LyXParagraph * par = this;
3877 par = par->TeXOnePar(buf, bparams,
3881 foot, foot_texrow, foot_count
3885 if (minipage_open && par && !style.isEnvironment() &&
3886 (par->pextra_type == PEXTRA_MINIPAGE) &&
3887 par->pextra_start_minipage) {
3888 os << "\\end{minipage}\n";
3890 if (par_sep == BufferParams::PARSEP_INDENT) {
3894 minipage_open = false;
3896 if (par && par->depth > depth) {
3897 if (textclasslist.Style(bparams.textclass,
3898 par->layout).isParagraph()
3901 // How to handle this? (Lgb)
3902 //&& !suffixIs(os, "\n\n")
3904 // There should be at least one '\n' already
3905 // but we need there to be two for Standard
3906 // paragraphs that are depth-increment'ed to be
3907 // output correctly. However, tables can
3908 // also be paragraphs so don't adjust them.
3911 // Will it ever harm to have one '\n' too
3912 // many? i.e. that we sometimes will have
3913 // three in a row. (Lgb)
3917 par = par->TeXDeeper(buf, bparams, os, texrow,
3918 foot, foot_texrow, foot_count);
3920 if (par && par->layout == layout && par->depth == depth &&
3921 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3922 if (par->pextra_hfill && par->Previous() &&
3923 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3924 os << "\\hfill{}\n";
3927 if (par_sep == BufferParams::PARSEP_INDENT) {
3928 os << "{\\setlength\\parindent{0pt}\n";
3931 os << "\\begin{minipage}";
3932 switch(par->pextra_alignment) {
3933 case MINIPAGE_ALIGN_TOP:
3936 case MINIPAGE_ALIGN_MIDDLE:
3939 case MINIPAGE_ALIGN_BOTTOM:
3943 if (!par->pextra_width.empty()) {
3944 os << '{' << par->pextra_width << "}\n";
3946 //float ib = atof(par->pextra_widthp.c_str())/100;
3947 // string can't handle floats at present
3948 // so I'll do a conversion by hand knowing that
3949 // the limits are 0.0 to 1.0. ARRae.
3951 switch (par->pextra_widthp.length()) {
3956 os << "0." << par->pextra_widthp;
3959 os << "0.0" << par->pextra_widthp;
3961 os << "\\columnwidth}\n";
3964 if (par_sep == BufferParams::PARSEP_INDENT) {
3965 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3968 minipage_open = true;
3969 minipage_open_depth = par->depth;
3972 && par->layout == layout
3973 && par->depth == depth
3974 && par->pextra_type == pextra_type
3976 && par->footnoteflag == footnoteflag
3980 if (style.isEnvironment()) {
3981 os << "\\end{" << style.latexname() << '}';
3982 // maybe this should go after the minipage closes?
3983 if (foot_this_level) {
3984 if (foot_count >= 1) {
3985 if (foot_count > 1) {
3986 os << "\\addtocounter{footnote}{-"
3991 texrow += foot_texrow;
3993 foot_texrow.reset();
3998 if (minipage_open && (minipage_open_depth == depth) &&
3999 (!par || par->pextra_start_minipage ||
4000 par->pextra_type != PEXTRA_MINIPAGE)) {
4001 os << "\\end{minipage}\n";
4003 if (par_sep == BufferParams::PARSEP_INDENT) {
4007 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
4008 os << "\\medskip\n\n";
4012 minipage_open = false;
4015 os << "\\end{LyXParagraphIndent}\n";
4018 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
4019 && par->pextra_hfill)) {
4023 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
4024 return par; // ale970302
4029 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
4030 BufferParams const & bparams,
4031 ostream & os, TexRow & texrow,
4032 ostream & foot, TexRow & foot_texrow,
4036 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
4037 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
4038 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4039 "No footnote!" << endl;
4041 LyXParagraph * par = this;
4042 LyXLayout const & style =
4043 textclasslist.Style(bparams.textclass,
4044 previous->GetLayout());
4046 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
4047 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4048 "Float other than footnote in command"
4049 " with moving argument is illegal" << endl;
4052 if (footnotekind != LyXParagraph::FOOTNOTE
4053 && footnotekind != LyXParagraph::MARGIN
4056 // How to solve this?
4057 //&& !suffixIs(file, '\n')
4059 // we need to ensure that real floats like tables and figures
4060 // have their \begin{} on a new line otherwise we can get
4061 // incorrect results when using the endfloat.sty package
4062 // especially if two floats follow one another. ARRae 981022
4063 // NOTE: if the file is length 0 it must have just been
4064 // written out so we assume it ended with a '\n'
4066 // As far as I can see there is never any harm in writing
4067 // a '\n' too much. Please tell me if I am wrong. (Lgb)
4072 bool moving_arg = false;
4073 bool need_closing = false;
4074 bool is_rtl = isRightToLeftPar(bparams);
4076 if (is_rtl != parent_is_rtl) {
4081 need_closing = true;
4084 //BufferParams * params = ¤t_view->buffer()->params;
4085 bool footer_in_body = true;
4086 switch (footnotekind) {
4087 case LyXParagraph::FOOTNOTE:
4088 if (style.intitle) {
4089 os << "\\thanks{\n";
4090 footer_in_body = false;
4093 if (foot_count == -1) {
4094 // we're at depth 0 so we can use:
4095 os << "\\footnote{%\n";
4096 footer_in_body = false;
4098 os << "\\footnotemark{}%\n";
4100 // we only need this when there are
4101 // multiple footnotes
4102 os << "\\stepcounter{footnote}";
4104 os << "\\footnotetext{%\n";
4105 foot_texrow.start(this, 0);
4106 foot_texrow.newline();
4111 case LyXParagraph::MARGIN:
4112 os << "\\marginpar{\n";
4114 case LyXParagraph::FIG:
4115 if (pextra_type == PEXTRA_FLOATFLT
4116 && (!pextra_width.empty()
4117 || !pextra_widthp.empty())) {
4118 if (!pextra_width.empty())
4119 os << "\\begin{floatingfigure}{"
4120 << pextra_width << "}\n";
4122 os << "\\begin{floatingfigure}{"
4123 << atoi(pextra_widthp.c_str())/100.0
4124 << "\\textwidth}\n";
4126 os << "\\begin{figure}";
4127 if (!bparams.float_placement.empty()) {
4128 os << '[' << bparams.float_placement << "]\n";
4134 case LyXParagraph::TAB:
4135 os << "\\begin{table}";
4136 if (!bparams.float_placement.empty()) {
4137 os << '[' << bparams.float_placement << "]\n";
4142 case LyXParagraph::WIDE_FIG:
4143 os << "\\begin{figure*}";
4144 if (!bparams.float_placement.empty()) {
4145 os << '[' << bparams.float_placement << "]\n";
4150 case LyXParagraph::WIDE_TAB:
4151 os << "\\begin{table*}";
4152 if (!bparams.float_placement.empty()) {
4153 os << '[' << bparams.float_placement << "]\n";
4158 case LyXParagraph::ALGORITHM:
4159 os << "\\begin{algorithm}\n";
4164 if (footnotekind != LyXParagraph::FOOTNOTE
4165 || !footer_in_body) {
4166 // Process text for all floats except footnotes in body
4168 LyXLayout const & style =
4170 .Style(bparams.textclass, par->layout);
4172 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4174 if (style.isEnvironment()
4175 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4176 // Allows the use of minipages within float
4177 // environments. Shouldn't be circular because
4178 // we don't support footnotes inside
4179 // floats (yet). ARRae
4180 par = par->TeXEnvironment(buf, bparams, os,
4185 par = par->TeXOnePar(buf, bparams,
4186 os, texrow, moving_arg,
4191 if (par && !par->IsDummy() && par->depth > depth) {
4192 par = par->TeXDeeper(buf, bparams, os, texrow,
4196 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4198 // process footnotes > depth 0 or in environments separately
4199 // NOTE: Currently don't support footnotes within footnotes
4200 // even though that is possible using the \footnotemark
4202 std::ostringstream dummy;
4206 TexRow dummy_texrow;
4207 int dummy_count = 0;
4209 LyXLayout const & style =
4211 .Style(bparams.textclass, par->layout);
4213 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4215 if (style.isEnvironment()
4216 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4217 // Allows the use of minipages within float
4218 // environments. Shouldn't be circular because
4219 // we don't support footnotes inside
4220 // floats (yet). ARRae
4221 par = par->TeXEnvironment(buf, bparams,
4223 dummy, dummy_texrow,
4226 par = par->TeXOnePar(buf, bparams,
4229 dummy, dummy_texrow,
4233 if (par && !par->IsDummy() && par->depth > depth) {
4234 par = par->TeXDeeper(buf, bparams,
4236 dummy, dummy_texrow,
4240 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4242 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4243 "Footnote in a Footnote -- not supported"
4246 #ifndef HAVE_OSTREAM
4247 delete [] dummy.str();
4251 switch (footnotekind) {
4252 case LyXParagraph::FOOTNOTE:
4253 if (footer_in_body) {
4254 // This helps tell which of the multiple
4255 // footnotetexts an error was in.
4257 foot_texrow.newline();
4262 case LyXParagraph::MARGIN:
4265 case LyXParagraph::FIG:
4266 if (pextra_type == PEXTRA_FLOATFLT
4267 && (!pextra_width.empty()
4268 || !pextra_widthp.empty()))
4269 os << "\\end{floatingfigure}";
4271 os << "\\end{figure}";
4273 case LyXParagraph::TAB:
4274 os << "\\end{table}";
4276 case LyXParagraph::WIDE_FIG:
4277 os << "\\end{figure*}";
4279 case LyXParagraph::WIDE_TAB:
4280 os << "\\end{table*}";
4282 case LyXParagraph::ALGORITHM:
4283 os << "\\end{algorithm}";
4290 if (footnotekind != LyXParagraph::FOOTNOTE
4291 && footnotekind != LyXParagraph::MARGIN) {
4292 // we need to ensure that real floats like tables and figures
4293 // have their \end{} on a line of their own otherwise we can
4294 // get incorrect results when using the endfloat.sty package.
4299 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4304 bool LyXParagraph::IsDummy() const
4306 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4307 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4311 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4312 int type, char const * width,
4313 char const * widthp)
4316 pextra_width = width;
4317 pextra_widthp = widthp;
4319 if (textclasslist.Style(bparams.textclass,
4320 layout).isEnvironment()) {
4325 while (par && (par->layout == layout)
4326 && (par->depth == depth)) {
4328 par = par->Previous();
4331 par = par->FirstPhysicalPar();
4333 while (par && par->depth > depth) {
4334 par = par->Previous();
4337 par = par->FirstPhysicalPar();
4342 while (par && (par->layout == layout)
4343 && (par->depth == depth)) {
4344 par->pextra_type = type;
4345 par->pextra_width = width;
4346 par->pextra_widthp = widthp;
4348 par = par->NextAfterFootnote();
4352 if (par && (par->depth > depth))
4353 par->SetPExtraType(bparams,
4354 type, width, widthp);
4356 while (par && ((par->depth > depth) || par->IsDummy()))
4357 par = par->NextAfterFootnote();
4359 while (par && ((par->depth > depth)))
4367 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4369 if (pextra_type == PEXTRA_NONE)
4372 pextra_type = PEXTRA_NONE;
4373 pextra_width.erase();
4374 pextra_widthp.erase();
4376 if (textclasslist.Style(bparams.textclass,
4377 layout).isEnvironment()) {
4382 while (par && (par->layout == layout)
4383 && (par->depth == depth)) {
4385 par = par->Previous();
4388 par = par->FirstPhysicalPar();
4390 while (par && par->depth > depth) {
4391 par = par->Previous();
4394 par = par->FirstPhysicalPar();
4399 while (par && (par->layout == layout)
4400 && (par->depth == depth)) {
4401 par->pextra_type = PEXTRA_NONE;
4402 par->pextra_width.erase();
4403 par->pextra_widthp.erase();
4405 par = par->NextAfterFootnote();
4409 if (par && (par->depth > depth))
4410 par->UnsetPExtraType(bparams);
4412 while (par && ((par->depth > depth) || par->IsDummy()))
4413 par = par->NextAfterFootnote();
4415 while (par && ((par->depth > depth)))
4423 bool LyXParagraph::IsHfill(size_type pos) const
4425 return IsHfillChar(GetChar(pos));
4429 bool LyXParagraph::IsInset(size_type pos) const
4431 return IsInsetChar(GetChar(pos));
4436 bool LyXParagraph::IsFloat(size_type pos) const
4438 return IsFloatChar(GetChar(pos));
4443 bool LyXParagraph::IsNewline(size_type pos) const
4445 return pos >= 0 && IsNewlineChar(GetChar(pos));
4449 bool LyXParagraph::IsSeparator(size_type pos) const
4451 return IsSeparatorChar(GetChar(pos));
4455 bool LyXParagraph::IsLineSeparator(size_type pos) const
4457 return IsLineSeparatorChar(GetChar(pos));
4461 bool LyXParagraph::IsKomma(size_type pos) const
4463 return IsKommaChar(GetChar(pos));
4467 /// Used by the spellchecker
4468 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4470 value_type c = GetChar(pos);
4471 if (IsLetterChar(c))
4473 // '\0' is not a letter, allthough every string contains "" (below)
4476 // We want to pass the ' and escape chars to ispell
4477 string extra = lyxrc.isp_esc_chars + '\'';
4481 return contains(extra, ch);
4485 bool LyXParagraph::IsWord(size_type pos ) const
4487 return IsWordChar(GetChar(pos)) ;
4492 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4496 return FirstPhysicalPar()->getParLanguage(bparams);
4503 return GetFirstFontSettings().language();
4506 for (size_type pos = 0; pos < size(); ++pos)
4508 return GetFontSettings(bparams, pos).language();
4509 return GetFirstFontSettings().language();
4513 return previous->getParLanguage(bparams);
4515 return bparams.language_info;
4519 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4521 return lyxrc.rtl_support && !table
4522 && getParLanguage(bparams)->RightToLeft();
4526 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4527 Language const * from, Language const * to)
4529 for(size_type i = 0; i < size(); ++i) {
4530 LyXFont font = GetFontSettings(bparams, i);
4531 if (font.language() == from) {
4532 font.setLanguage(to);
4539 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4541 Language const * doc_language = bparams.language_info;
4542 for (FontList::const_iterator cit = fontlist.begin();
4543 cit != fontlist.end(); ++cit)
4544 if ((*cit).font.language() != doc_language)
4550 // Convert the paragraph to a string.
4551 // Used for building the table of contents
4552 string LyXParagraph::String(Buffer const * buffer, bool label)
4554 BufferParams const & bparams = buffer->params;
4557 if (label && !IsDummy() && !labelstring.empty())
4559 if (label && !labelstring.empty())
4561 s += labelstring + ' ';
4562 string::size_type len = s.size();
4564 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4565 value_type c = GetChar(i);
4568 else if (c == META_INSET &&
4569 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4571 std::ostringstream ost;
4572 GetInset(i)->Ascii(buffer, ost);
4575 GetInset(i)->Ascii(buffer, ost);
4578 s += subst(ost.str(),'\n',' ');
4583 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4584 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4585 s += NextAfterFootnote()->String(buffer, false);
4589 if (isRightToLeftPar(bparams))
4590 reverse(s.begin() + len,s.end());
4598 string LyXParagraph::String(Buffer const * buffer,
4599 LyXParagraph::size_type beg,
4600 LyXParagraph::size_type end)
4607 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4609 if (cell >= table->NumberOfCellsInRow(actcell))
4618 if (beg == 0 && !IsDummy() && !labelstring.empty())
4620 if (beg == 0 && !labelstring.empty())
4622 s += labelstring + ' ';
4624 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4625 value_type c = GetChar(i);
4628 else if (c == META_INSET) {
4630 std::ostringstream ost;
4631 GetInset(i)->Ascii(buffer, ost);
4634 GetInset(i)->Ascii(buffer, ost);
4638 } else if (table && IsNewlineChar(c)) {
4639 if (cell >= table->NumberOfCellsInRow(actcell)) {
4654 void LyXParagraph::SetInsetOwner(Inset *i)
4657 for (InsetList::const_iterator cit = insetlist.begin();
4658 cit != insetlist.end(); ++cit) {
4660 (*cit).inset->setOwner(i);
4665 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4668 for (InsetList::const_iterator cit = insetlist.begin();
4669 cit != insetlist.end(); ++cit) {
4671 if ((*cit).inset->IsTextInset()) {
4672 static_cast<UpdatableInset *>
4673 ((*cit).inset)->deleteLyXText(bv);
4680 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4683 for (InsetList::const_iterator cit = insetlist.begin();
4684 cit != insetlist.end(); ++cit) {
4686 if ((*cit).inset->IsTextInset()) {
4687 static_cast<UpdatableInset *>
4688 ((*cit).inset)->resizeLyXText(bv);