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);
2580 LyXParagraph * p = 0;
2583 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2584 (p = PreviousBeforeFootnote()) != 0)
2585 last_font = p->getFont(bparams, p->size() - 1);
2588 last_font = running_font;
2590 // Spaces at end of font change are simulated to be
2591 // outside font change, i.e. we write "\textXX{text} "
2592 // rather than "\textXX{text }". (Asger)
2593 if (open_font && c == ' ' && i <= size() - 2
2594 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2595 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2596 font = getFont(bparams, i + 1);
2598 // We end font definition before blanks
2599 if (!font.equalExceptLatex(running_font) && open_font) {
2600 column += running_font.latexWriteEndChanges(os,
2602 (i == main_body-1) ? basefont : font);
2603 running_font = basefont;
2607 // Blanks are printed before start of fontswitch
2609 // Do not print the separation of the optional argument
2610 if (i != main_body - 1) {
2611 SimpleTeXBlanks(os, texrow, i,
2612 column, font, style);
2616 // Do we need to change font?
2617 if (!font.equalExceptLatex(running_font)
2618 && i != main_body-1) {
2619 column += font.latexWriteStartChanges(os, basefont,
2621 running_font = font;
2625 if (c == LyXParagraph::META_NEWLINE) {
2626 // newlines are handled differently here than
2627 // the default in SimpleTeXSpecialChars().
2628 if (!style.newline_allowed
2629 || font.latex() == LyXFont::ON) {
2633 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2636 basefont = getFont(bparams, -1);
2637 running_font = basefont;
2638 if (font.family() ==
2639 LyXFont::TYPEWRITER_FAMILY) {
2647 texrow.start(this, i + 1);
2650 SimpleTeXSpecialChars(buf, bparams,
2651 os, texrow, moving_arg,
2652 font, running_font, basefont,
2653 open_font, style, i, column, c);
2657 // If we have an open font definition, we have to close it
2659 LyXParagraph * p = 0;
2662 && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2663 && (p = NextAfterFootnote()) != 0
2668 running_font.latexWriteEndChanges(os, basefont,
2669 p->getFont(bparams, 0));
2671 running_font.latexWriteEndChanges(os, basefont, basefont);
2674 // Needed if there is an optional argument but no contents.
2675 if (main_body > 0 && main_body == size()) {
2677 return_value = false;
2680 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2681 return return_value;
2685 // This one spits out the text of a table paragraph
2686 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2687 BufferParams const & bparams,
2688 ostream & os, TexRow & texrow)
2690 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2692 bool return_value = false;
2694 LyXLayout const & style =
2695 textclasslist.Style(bparams.textclass, GetLayout());
2699 if (!IsDummy()) { // it is dummy if it is in a float!!!
2701 if (style.isCommand()) {
2704 } else if (align != LYX_ALIGN_LAYOUT) {
2707 return_value = true;
2710 os << "\\noindent ";
2714 case LYX_ALIGN_NONE:
2715 case LYX_ALIGN_BLOCK:
2716 case LYX_ALIGN_LAYOUT:
2717 case LYX_ALIGN_SPECIAL: break;
2718 case LYX_ALIGN_LEFT:
2719 os << "\\raggedright ";
2722 case LYX_ALIGN_RIGHT:
2723 os << "\\raggedleft ";
2726 case LYX_ALIGN_CENTER:
2727 os << "\\centering ";
2735 LyXFont basefont = getFont(bparams, -1); // Get layout font
2736 // Which font is currently active?
2737 LyXFont running_font = basefont;
2739 // Do we have an open font change?
2740 bool open_font = false;
2741 int current_cell_number = -1;
2742 int tmp = table->TexEndOfCell(os, current_cell_number);
2743 for (; tmp > 0 ; --tmp)
2746 texrow.start(this, 0);
2748 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2749 bool first_in_cell = true;
2751 for (size_type i = 0; i < size(); ++i) {
2752 value_type c = GetChar(i);
2753 if (table->IsContRow(current_cell_number + 1)) {
2754 if (c == LyXParagraph::META_NEWLINE)
2755 ++current_cell_number;
2760 if (first_in_cell && is_rtl) {
2763 first_in_cell = false;
2766 // Fully instantiated font
2767 LyXFont font = getFont(bparams, i);
2768 last_font = running_font;
2770 // Spaces at end of font change are simulated to be
2771 // outside font change.
2772 // i.e. we write "\textXX{text} " rather than
2773 // "\textXX{text }". (Asger)
2774 if (open_font && c == ' ' && i <= size() - 2
2775 && getFont(bparams, i + 1) != running_font
2776 && getFont(bparams, i + 1) != font) {
2777 font = getFont(bparams, i + 1);
2780 // We end font definition before blanks
2781 if (font != running_font && open_font) {
2782 column += running_font.latexWriteEndChanges(os,
2785 running_font = basefont;
2788 // Blanks are printed before start of fontswitch
2790 SimpleTeXBlanks(os, texrow, i, column, font, style);
2792 // Do we need to change font?
2793 if (font != running_font) {
2794 column += font.latexWriteStartChanges(os, basefont,
2796 running_font = font;
2799 // Do we need to turn on LaTeX mode?
2800 if (font.latex() != running_font.latex()) {
2801 if (font.latex() == LyXFont::ON
2802 && style.needprotect) {
2807 if (c == LyXParagraph::META_NEWLINE) {
2808 // special case for inside a table
2809 // different from default case in
2810 // SimpleTeXSpecialChars()
2812 column += running_font
2813 .latexWriteEndChanges(os, basefont,
2817 basefont = getFont(bparams, -1);
2818 running_font = basefont;
2819 ++current_cell_number;
2820 if (table->CellHasContRow(current_cell_number) >= 0) {
2821 TeXContTableRows(buf, bparams, os, i + 1,
2822 current_cell_number,
2825 if (is_rtl && !first_in_cell) {
2827 first_in_cell = true;
2830 // if this cell follow only ContRows till end don't
2831 // put the EndOfCell because it is put after the
2833 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2834 --current_cell_number;
2837 int tmp = table->TexEndOfCell(os,
2838 current_cell_number);
2841 } else if (tmp < 0) {
2847 texrow.start(this, i + 1);
2849 SimpleTeXSpecialChars(buf, bparams,
2851 font, running_font, basefont,
2852 open_font, style, i, column, c);
2856 // If we have an open font definition, we have to close it
2858 running_font.latexWriteEndChanges(os, basefont, basefont);
2860 ++current_cell_number;
2861 if (is_rtl && !first_in_cell)
2863 tmp = table->TexEndOfCell(os, current_cell_number);
2864 for (; tmp > 0; --tmp)
2866 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2867 return return_value;
2871 // This one spits out the text off ContRows in tables
2872 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2873 BufferParams const & bparams,
2875 LyXParagraph::size_type i,
2876 int current_cell_number,
2877 int & column, TexRow & texrow)
2879 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2883 bool return_value = false;
2884 LyXLayout const & style =
2885 textclasslist.Style(bparams.textclass,
2887 LyXFont basefont = getFont(bparams, -1); // Get layout font
2889 // Which font is currently active?
2890 LyXFont running_font = basefont;
2891 // Do we have an open font change?
2892 bool open_font = false;
2894 size_type lastpos = i;
2895 int cell = table->CellHasContRow(current_cell_number);
2896 ++current_cell_number;
2899 // first find the right position
2901 for (; (i < size()) && (current_cell_number < cell); ++i) {
2903 if (c == LyXParagraph::META_NEWLINE)
2904 ++current_cell_number;
2908 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2912 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2917 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2921 // Fully instantiated font
2922 LyXFont font = getFont(bparams, i);
2923 last_font = running_font;
2925 // Spaces at end of font change are simulated to
2926 // be outside font change. i.e. we write
2927 // "\textXX{text} " rather than "\textXX{text }".
2929 if (open_font && c == ' ' && i <= size() - 2
2930 && getFont(bparams, i + 1) != running_font
2931 && getFont(bparams, i + 1) != font) {
2932 font = getFont(bparams, i + 1);
2935 // We end font definition before blanks
2936 if (font != running_font && open_font) {
2937 column += running_font.latexWriteEndChanges(os, basefont, font);
2938 running_font = basefont;
2941 // Blanks are printed before start of fontswitch
2943 SimpleTeXBlanks(os, texrow, i,
2944 column, font, style);
2946 // Do we need to change font?
2947 if (font != running_font) {
2949 font.latexWriteStartChanges(os,
2952 running_font = font;
2955 // Do we need to turn on LaTeX mode?
2956 if (font.latex() != running_font.latex()) {
2957 if (font.latex() == LyXFont::ON
2958 && style.needprotect) {
2963 SimpleTeXSpecialChars(buf, bparams,
2964 os, texrow, false, font,
2965 running_font, basefont,
2966 open_font, style, i, column, c);
2968 // If we have an open font definition, we have to close it
2970 running_font.latexWriteEndChanges(os, basefont,
2974 basefont = getFont(bparams, -1);
2975 running_font = basefont;
2976 cell = table->CellHasContRow(current_cell_number);
2978 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2979 return return_value;
2983 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2985 bool retval = false;
2987 case LyXParagraph::META_HFILL:
2988 sgml_string.erase();
2990 case LyXParagraph::META_NEWLINE:
2994 sgml_string = "&";
2997 sgml_string = "<";
3000 sgml_string = ">";
3003 sgml_string = "$";
3006 sgml_string = "#";
3009 sgml_string = "%";
3012 sgml_string = "[";
3015 sgml_string = "]";
3018 sgml_string = "{";
3021 sgml_string = "}";
3024 sgml_string = "˜";
3027 sgml_string = """;
3030 sgml_string = "\";
3036 case '\0': // Ignore :-)
3037 sgml_string.erase();
3047 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
3048 ostream & os, string & extra,
3049 int & desc_on, int depth)
3051 BufferParams const & bparams = buffer->params;
3053 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
3055 LyXFont font1, font2;
3058 size_type main_body;
3059 bool emph_flag = false;
3061 LyXLayout const & style =
3062 textclasslist.Style(bparams.textclass,
3065 if (style.labeltype != LABEL_MANUAL)
3068 main_body = BeginningOfMainBody();
3070 // Gets paragraph main font.
3072 font1 = style.labelfont;
3076 int char_line_count = depth;
3077 os << newlineAndDepth(depth);
3079 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3080 os << "<INFORMALTABLE>"
3081 << newlineAndDepth(++depth);
3084 os << "<INFORMALTABLE>"
3085 << newlineAndDepth(++depth);
3087 int current_cell_number = -1;
3088 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3090 // Parsing main loop.
3091 for (size_type i = 0; i < size(); ++i) {
3093 if (table->IsContRow(current_cell_number+1)) {
3094 if (c == LyXParagraph::META_NEWLINE)
3095 ++current_cell_number;
3100 // Fully instantiated font
3101 font2 = getFont(bparams, i);
3103 // Handle <emphasis> tag.
3104 if (font1.emph() != font2.emph() && i) {
3105 if (font2.emph() == LyXFont::ON) {
3108 } else if (emph_flag) {
3109 os << "</emphasis>";
3113 if (c == LyXParagraph::META_NEWLINE) {
3114 // We have only to control for emphasis open here!
3116 os << "</emphasis>";
3119 font1 = font2 = getFont(bparams, -1);
3120 ++current_cell_number;
3121 if (table->CellHasContRow(current_cell_number) >= 0) {
3122 DocBookContTableRows(buffer,
3123 os, extra, desc_on, i + 1,
3124 current_cell_number,
3127 // if this cell follow only ContRows till end don't
3128 // put the EndOfCell because it is put after the
3130 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3131 --current_cell_number;
3134 tmp = table->DocBookEndOfCell(os,
3135 current_cell_number,
3140 } else if (c == LyXParagraph::META_INSET) {
3141 inset = GetInset(i);
3143 std::ostringstream ost;
3144 inset->DocBook(buffer, ost);
3145 string tmp_out = ost.str().c_str();
3148 inset->DocBook(buffer, ost);
3150 char * ctmp = ost.str();
3151 string tmp_out(ctmp);
3155 // This code needs some explanation:
3156 // Two insets are treated specially
3157 // label if it is the first element in a
3158 // command paragraph
3160 // graphics inside tables or figure floats
3162 // title (the equivalente in latex for this
3164 // and title should come first
3167 if(desc_on != 3 || i != 0) {
3168 if(tmp_out[0] == '@') {
3170 extra += frontStrip(tmp_out,
3173 os << frontStrip(tmp_out,
3178 } else if (font2.latex() == LyXFont::ON) {
3179 // "TeX"-Mode on == > SGML-Mode on.
3185 if (linuxDocConvertChar(c, sgml_string)
3186 && !style.free_spacing) {
3187 // in freespacing mode, spaces are
3188 // non-breaking characters
3193 << "</term><listitem><para>";
3205 // Needed if there is an optional argument but no contents.
3206 if (main_body > 0 && main_body == size()) {
3211 os << "</emphasis>";
3214 ++current_cell_number;
3215 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3216 // Resets description flag correctly.
3219 // <term> not closed...
3224 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3226 os << "</INFORMALTABLE>";
3228 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3233 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3234 ostream & os, string & extra,
3236 LyXParagraph::size_type i,
3237 int current_cell_number, int &column)
3242 BufferParams const & bparams = buffer->params;
3244 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3249 //string emph = "emphasis";
3250 bool emph_flag = false;
3251 int char_line_count = 0;
3253 LyXLayout const & style =
3254 textclasslist.Style(bparams.textclass,
3257 size_type main_body;
3258 if (style.labeltype != LABEL_MANUAL)
3261 main_body = BeginningOfMainBody();
3263 // Gets paragraph main font.
3266 font1 = style.labelfont;
3270 size_type lastpos = i;
3271 int cell = table->CellHasContRow(current_cell_number);
3272 ++current_cell_number;
3274 // first find the right position
3276 for (; i < size() && current_cell_number < cell; ++i) {
3278 if (c == LyXParagraph::META_NEWLINE)
3279 ++current_cell_number;
3283 // I don't know how to handle this so I comment it
3284 // for the moment (Jug)
3285 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3286 // file += " \\\\\n";
3289 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3294 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3298 // Fully instantiated font
3299 font2 = getFont(bparams, i);
3301 // Handle <emphasis> tag.
3302 if (font1.emph() != font2.emph() && i) {
3303 if (font2.emph() == LyXFont::ON) {
3306 } else if (emph_flag) {
3307 os << "</emphasis>";
3311 if (c == LyXParagraph::META_INSET) {
3312 inset = GetInset(i);
3314 std::ostringstream ost;
3315 inset->DocBook(buffer, ost);
3316 string tmp_out = ost.str().c_str();
3319 inset->DocBook(buffer, ost);
3321 char * ctmp = ost.str();
3322 string tmp_out(ctmp);
3326 // This code needs some explanation:
3327 // Two insets are treated specially
3328 // label if it is the first element in a
3329 // command paragraph
3331 // graphics inside tables or figure floats
3332 // can't go on title (the equivalente in
3333 // latex for this case is caption and title
3334 // should come first
3337 if(desc_on != 3 || i != 0) {
3338 if(tmp_out[0] == '@') {
3340 extra += frontStrip(tmp_out, '@');
3342 os << frontStrip(tmp_out, '@');
3346 } else if (font2.latex() == LyXFont::ON) {
3347 // "TeX"-Mode on == > SGML-Mode on.
3353 if (linuxDocConvertChar(c, sgml_string)
3354 && !style.free_spacing) {
3355 // in freespacing mode, spaces are
3356 // non-breaking characters
3361 << "</term><listitem><para>";
3371 // we have only to control for emphasis open here!
3373 os << "</emphasis>";
3376 font1 = font2 = getFont(bparams, -1);
3377 cell = table->CellHasContRow(current_cell_number);
3379 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3383 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3384 LyXParagraph::size_type const i,
3385 int & column, LyXFont const & font,
3386 LyXLayout const & style)
3388 if (column > tex_code_break_column
3390 && GetChar(i - 1) != ' '
3392 // In LaTeX mode, we don't want to
3393 // break lines since some commands
3395 && ! (font.latex() == LyXFont::ON)
3396 // same in FreeSpacing mode
3397 && !style.free_spacing
3398 // In typewriter mode, we want to avoid
3399 // ! . ? : at the end of a line
3400 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3401 && (GetChar(i-1) == '.'
3402 || GetChar(i-1) == '?'
3403 || GetChar(i-1) == ':'
3404 || GetChar(i-1) == '!'))) {
3405 if (tex_code_break_column == 0) {
3406 // in batchmode we need LaTeX to still
3407 // see it as a space not as an extra '\n'
3413 texrow.start(this, i + 1);
3415 } else if (font.latex() == LyXFont::OFF) {
3416 if (style.free_spacing) {
3425 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3426 BufferParams const & bparams,
3427 ostream & os, TexRow & texrow,
3430 LyXFont & running_font,
3433 LyXLayout const & style,
3434 LyXParagraph::size_type & i,
3436 LyXParagraph::value_type const c)
3438 // Two major modes: LaTeX or plain
3439 // Handle here those cases common to both modes
3440 // and then split to handle the two modes separately.
3442 case LyXParagraph::META_INSET: {
3443 Inset * inset = GetInset(i);
3446 int len = os.tellp();
3447 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3448 || inset->LyxCode() == Inset::MATH_CODE
3449 || inset->LyxCode() == Inset::URL_CODE)
3450 && running_font.isRightToLeft()) {
3455 int tmp = inset->Latex(buf, os, moving_arg,
3456 style.free_spacing);
3464 column += os.tellp() - len;
3473 case LyXParagraph::META_NEWLINE:
3475 column += running_font.latexWriteEndChanges(os,
3480 basefont = getFont(bparams, -1);
3481 running_font = basefont;
3484 case LyXParagraph::META_HFILL:
3490 // And now for the special cases within each mode
3491 // Are we in LaTeX mode?
3492 if (font.latex() == LyXFont::ON) {
3493 // at present we only have one option
3494 // but I'll leave it as a switch statement
3495 // so its simpler to extend. (ARRae)
3498 // make sure that we will not print
3499 // error generating chars to the tex
3500 // file. This test would not be needed
3501 // if it were done in the buffer
3509 // Plain mode (i.e. not LaTeX)
3512 os << "\\textbackslash{}";
3516 case '°': case '±': case '²': case '³':
3517 case '×': case '÷': case '¹': case 'ª':
3518 case 'º': case '¬': case 'µ':
3519 if (bparams.inputenc == "latin1" ||
3520 (bparams.inputenc == "auto" &&
3521 font.language()->encoding()->LatexName()
3523 os << "\\ensuremath{"
3532 case '|': case '<': case '>':
3533 // In T1 encoding, these characters exist
3534 if (lyxrc.fontenc == "T1") {
3536 //... but we should avoid ligatures
3537 if ((c == '>' || c == '<')
3539 && GetChar(i + 1) == c) {
3540 //os << "\\textcompwordmark{}";
3541 // Jean-Marc, have a look at
3542 // this. IÂ think this works
3550 // Typewriter font also has them
3551 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3555 // Otherwise, we use what LaTeX
3559 os << "\\textless{}";
3563 os << "\\textgreater{}";
3567 os << "\\textbar{}";
3573 case '-': // "--" in Typewriter mode -> "-{}-"
3575 && GetChar(i + 1) == '-'
3576 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3585 os << "\\char`\\\"{}";
3590 if (bparams.inputenc == "default") {
3599 case '%': case '#': case '{':
3606 os << "\\textasciitilde{}";
3611 os << "\\textasciicircum{}";
3615 case '*': case '[': case ']':
3616 // avoid being mistaken for optional arguments
3617 os << '{' << c << '}';
3622 // Blanks are printed before font switching.
3623 // Sure? I am not! (try nice-latex)
3624 // I am sure it's correct. LyX might be smarter
3625 // in the future, but for now, nothing wrong is
3630 /* idea for labels --- begin*/
3634 && font.family() != LyXFont::TYPEWRITER_FAMILY
3635 && GetChar(i + 1) == 'y'
3636 && GetChar(i + 2) == 'X') {
3644 && font.family() != LyXFont::TYPEWRITER_FAMILY
3645 && GetChar(i + 1) == 'e'
3646 && GetChar(i + 2) == 'X') {
3651 // Check for "LaTeX2e"
3654 && font.family() != LyXFont::TYPEWRITER_FAMILY
3655 && GetChar(i + 1) == 'a'
3656 && GetChar(i + 2) == 'T'
3657 && GetChar(i + 3) == 'e'
3658 && GetChar(i + 4) == 'X'
3659 && GetChar(i + 5) == '2'
3660 && GetChar(i + 6) == 'e') {
3665 // Check for "LaTeX"
3668 && font.family() != LyXFont::TYPEWRITER_FAMILY
3669 && GetChar(i + 1) == 'a'
3670 && GetChar(i + 2) == 'T'
3671 && GetChar(i + 3) == 'e'
3672 && GetChar(i + 4) == 'X') {
3676 /* idea for labels --- end*/
3677 } else if (c != '\0') {
3687 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3688 BufferParams const & bparams,
3689 ostream & os, TexRow & texrow,
3691 TexRow & foot_texrow,
3694 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3695 LyXParagraph * par = this;
3698 (par->depth == depth)
3700 && (par->footnoteflag == footnoteflag)
3705 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3707 if (textclasslist.Style(bparams.textclass,
3708 par->layout).isEnvironment()
3709 || par->pextra_type != PEXTRA_NONE) {
3710 par = par->TeXEnvironment(buf, bparams,
3715 par = par->TeXOnePar(buf, bparams,
3725 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3731 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3732 BufferParams const & bparams,
3733 ostream & os, TexRow & texrow,
3735 TexRow & foot_texrow,
3738 bool eindent_open = false;
3739 bool foot_this_level = false;
3740 // flags when footnotetext should be appended to file.
3741 static bool minipage_open = false;
3742 static int minipage_open_depth = 0;
3743 char par_sep = bparams.paragraph_separation;
3745 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3748 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3751 LyXLayout const & style =
3752 textclasslist.Style(bparams.textclass,
3755 if (pextra_type == PEXTRA_INDENT) {
3756 if (!pextra_width.empty()) {
3757 os << "\\begin{LyXParagraphIndent}{"
3758 << pextra_width << "}\n";
3760 //float ib = atof(pextra_widthp.c_str())/100;
3761 // string can't handle floats at present (971109)
3762 // so I'll do a conversion by hand knowing that
3763 // the limits are 0.0 to 1.0. ARRae.
3764 os << "\\begin{LyXParagraphIndent}{";
3765 switch (pextra_widthp.length()) {
3777 os << "\\columnwidth}\n";
3780 eindent_open = true;
3782 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3783 if (pextra_hfill && Previous() &&
3784 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3785 os << "\\hfill{}\n";
3788 if (par_sep == BufferParams::PARSEP_INDENT) {
3789 os << "{\\setlength\\parindent{0pt}\n";
3792 os << "\\begin{minipage}";
3793 switch(pextra_alignment) {
3794 case MINIPAGE_ALIGN_TOP:
3797 case MINIPAGE_ALIGN_MIDDLE:
3800 case MINIPAGE_ALIGN_BOTTOM:
3804 if (!pextra_width.empty()) {
3805 os << '{' << pextra_width << "}\n";
3807 //float ib = atof(par->pextra_width.c_str())/100;
3808 // string can't handle floats at present
3809 // so I'll do a conversion by hand knowing that
3810 // the limits are 0.0 to 1.0. ARRae.
3812 switch (pextra_widthp.length()) {
3824 os << "\\columnwidth}\n";
3827 if (par_sep == BufferParams::PARSEP_INDENT) {
3828 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3831 minipage_open = true;
3832 minipage_open_depth = depth;
3835 #ifdef WITH_WARNINGS
3836 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3837 //I disabled it because it breaks when lists span on several
3840 if (style.isEnvironment()){
3841 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3842 #ifdef FANCY_FOOTNOTE_CODE
3843 if (foot_count < 0) {
3844 // flag that footnote[mark][text] should be
3845 // used for any footnotes from now on
3847 foot_this_level = true;
3850 os << "\\begin{" << style.latexname() << "}{"
3851 << labelwidthstring << "}\n";
3852 } else if (style.labeltype == LABEL_BIBLIO) {
3854 os << "\\begin{" << style.latexname() << "}{"
3855 << bibitemWidest(current_view)
3857 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3858 #ifdef FANCY_FOOTNOTE_CODE
3859 if (foot_count < 0) {
3860 // flag that footnote[mark][text] should be
3861 // used for any footnotes from now on
3863 foot_this_level = true;
3866 os << "\\begin{" << style.latexname() << '}'
3867 << style.latexparam() << '\n';
3869 os << "\\begin{" << style.latexname() << '}'
3870 << style.latexparam() << '\n';
3873 LyXParagraph * par = this;
3875 par = par->TeXOnePar(buf, bparams,
3879 foot, foot_texrow, foot_count
3883 if (minipage_open && par && !style.isEnvironment() &&
3884 (par->pextra_type == PEXTRA_MINIPAGE) &&
3885 par->pextra_start_minipage) {
3886 os << "\\end{minipage}\n";
3888 if (par_sep == BufferParams::PARSEP_INDENT) {
3892 minipage_open = false;
3894 if (par && par->depth > depth) {
3895 if (textclasslist.Style(bparams.textclass,
3896 par->layout).isParagraph()
3899 // How to handle this? (Lgb)
3900 //&& !suffixIs(os, "\n\n")
3902 // There should be at least one '\n' already
3903 // but we need there to be two for Standard
3904 // paragraphs that are depth-increment'ed to be
3905 // output correctly. However, tables can
3906 // also be paragraphs so don't adjust them.
3909 // Will it ever harm to have one '\n' too
3910 // many? i.e. that we sometimes will have
3911 // three in a row. (Lgb)
3915 par = par->TeXDeeper(buf, bparams, os, texrow,
3916 foot, foot_texrow, foot_count);
3918 if (par && par->layout == layout && par->depth == depth &&
3919 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3920 if (par->pextra_hfill && par->Previous() &&
3921 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3922 os << "\\hfill{}\n";
3925 if (par_sep == BufferParams::PARSEP_INDENT) {
3926 os << "{\\setlength\\parindent{0pt}\n";
3929 os << "\\begin{minipage}";
3930 switch(par->pextra_alignment) {
3931 case MINIPAGE_ALIGN_TOP:
3934 case MINIPAGE_ALIGN_MIDDLE:
3937 case MINIPAGE_ALIGN_BOTTOM:
3941 if (!par->pextra_width.empty()) {
3942 os << '{' << par->pextra_width << "}\n";
3944 //float ib = atof(par->pextra_widthp.c_str())/100;
3945 // string can't handle floats at present
3946 // so I'll do a conversion by hand knowing that
3947 // the limits are 0.0 to 1.0. ARRae.
3949 switch (par->pextra_widthp.length()) {
3954 os << "0." << par->pextra_widthp;
3957 os << "0.0" << par->pextra_widthp;
3959 os << "\\columnwidth}\n";
3962 if (par_sep == BufferParams::PARSEP_INDENT) {
3963 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3966 minipage_open = true;
3967 minipage_open_depth = par->depth;
3970 && par->layout == layout
3971 && par->depth == depth
3972 && par->pextra_type == pextra_type
3974 && par->footnoteflag == footnoteflag
3978 if (style.isEnvironment()) {
3979 os << "\\end{" << style.latexname() << '}';
3980 // maybe this should go after the minipage closes?
3981 if (foot_this_level) {
3982 if (foot_count >= 1) {
3983 if (foot_count > 1) {
3984 os << "\\addtocounter{footnote}{-"
3989 texrow += foot_texrow;
3991 foot_texrow.reset();
3996 if (minipage_open && (minipage_open_depth == depth) &&
3997 (!par || par->pextra_start_minipage ||
3998 par->pextra_type != PEXTRA_MINIPAGE)) {
3999 os << "\\end{minipage}\n";
4001 if (par_sep == BufferParams::PARSEP_INDENT) {
4005 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
4006 os << "\\medskip\n\n";
4010 minipage_open = false;
4013 os << "\\end{LyXParagraphIndent}\n";
4016 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
4017 && par->pextra_hfill)) {
4021 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
4022 return par; // ale970302
4027 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
4028 BufferParams const & bparams,
4029 ostream & os, TexRow & texrow,
4030 ostream & foot, TexRow & foot_texrow,
4034 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
4035 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
4036 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4037 "No footnote!" << endl;
4039 LyXParagraph * par = this;
4040 LyXLayout const & style =
4041 textclasslist.Style(bparams.textclass,
4042 previous->GetLayout());
4044 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
4045 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4046 "Float other than footnote in command"
4047 " with moving argument is illegal" << endl;
4050 if (footnotekind != LyXParagraph::FOOTNOTE
4051 && footnotekind != LyXParagraph::MARGIN
4054 // How to solve this?
4055 //&& !suffixIs(file, '\n')
4057 // we need to ensure that real floats like tables and figures
4058 // have their \begin{} on a new line otherwise we can get
4059 // incorrect results when using the endfloat.sty package
4060 // especially if two floats follow one another. ARRae 981022
4061 // NOTE: if the file is length 0 it must have just been
4062 // written out so we assume it ended with a '\n'
4064 // As far as I can see there is never any harm in writing
4065 // a '\n' too much. Please tell me if I am wrong. (Lgb)
4070 bool moving_arg = false;
4071 bool need_closing = false;
4072 bool is_rtl = isRightToLeftPar(bparams);
4074 if (is_rtl != parent_is_rtl) {
4079 need_closing = true;
4082 //BufferParams * params = ¤t_view->buffer()->params;
4083 bool footer_in_body = true;
4084 switch (footnotekind) {
4085 case LyXParagraph::FOOTNOTE:
4086 if (style.intitle) {
4087 os << "\\thanks{\n";
4088 footer_in_body = false;
4091 if (foot_count == -1) {
4092 // we're at depth 0 so we can use:
4093 os << "\\footnote{%\n";
4094 footer_in_body = false;
4096 os << "\\footnotemark{}%\n";
4098 // we only need this when there are
4099 // multiple footnotes
4100 os << "\\stepcounter{footnote}";
4102 os << "\\footnotetext{%\n";
4103 foot_texrow.start(this, 0);
4104 foot_texrow.newline();
4109 case LyXParagraph::MARGIN:
4110 os << "\\marginpar{\n";
4112 case LyXParagraph::FIG:
4113 if (pextra_type == PEXTRA_FLOATFLT
4114 && (!pextra_width.empty()
4115 || !pextra_widthp.empty())) {
4116 if (!pextra_width.empty())
4117 os << "\\begin{floatingfigure}{"
4118 << pextra_width << "}\n";
4120 os << "\\begin{floatingfigure}{"
4121 << atoi(pextra_widthp.c_str())/100.0
4122 << "\\textwidth}\n";
4124 os << "\\begin{figure}";
4125 if (!bparams.float_placement.empty()) {
4126 os << '[' << bparams.float_placement << "]\n";
4132 case LyXParagraph::TAB:
4133 os << "\\begin{table}";
4134 if (!bparams.float_placement.empty()) {
4135 os << '[' << bparams.float_placement << "]\n";
4140 case LyXParagraph::WIDE_FIG:
4141 os << "\\begin{figure*}";
4142 if (!bparams.float_placement.empty()) {
4143 os << '[' << bparams.float_placement << "]\n";
4148 case LyXParagraph::WIDE_TAB:
4149 os << "\\begin{table*}";
4150 if (!bparams.float_placement.empty()) {
4151 os << '[' << bparams.float_placement << "]\n";
4156 case LyXParagraph::ALGORITHM:
4157 os << "\\begin{algorithm}\n";
4162 if (footnotekind != LyXParagraph::FOOTNOTE
4163 || !footer_in_body) {
4164 // Process text for all floats except footnotes in body
4166 LyXLayout const & style =
4168 .Style(bparams.textclass, par->layout);
4170 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4172 if (style.isEnvironment()
4173 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4174 // Allows the use of minipages within float
4175 // environments. Shouldn't be circular because
4176 // we don't support footnotes inside
4177 // floats (yet). ARRae
4178 par = par->TeXEnvironment(buf, bparams, os,
4183 par = par->TeXOnePar(buf, bparams,
4184 os, texrow, moving_arg,
4189 if (par && !par->IsDummy() && par->depth > depth) {
4190 par = par->TeXDeeper(buf, bparams, os, texrow,
4194 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4196 // process footnotes > depth 0 or in environments separately
4197 // NOTE: Currently don't support footnotes within footnotes
4198 // even though that is possible using the \footnotemark
4200 std::ostringstream dummy;
4204 TexRow dummy_texrow;
4205 int dummy_count = 0;
4207 LyXLayout const & style =
4209 .Style(bparams.textclass, par->layout);
4211 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4213 if (style.isEnvironment()
4214 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4215 // Allows the use of minipages within float
4216 // environments. Shouldn't be circular because
4217 // we don't support footnotes inside
4218 // floats (yet). ARRae
4219 par = par->TeXEnvironment(buf, bparams,
4221 dummy, dummy_texrow,
4224 par = par->TeXOnePar(buf, bparams,
4227 dummy, dummy_texrow,
4231 if (par && !par->IsDummy() && par->depth > depth) {
4232 par = par->TeXDeeper(buf, bparams,
4234 dummy, dummy_texrow,
4238 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4240 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4241 "Footnote in a Footnote -- not supported"
4244 #ifndef HAVE_OSTREAM
4245 delete [] dummy.str();
4249 switch (footnotekind) {
4250 case LyXParagraph::FOOTNOTE:
4251 if (footer_in_body) {
4252 // This helps tell which of the multiple
4253 // footnotetexts an error was in.
4255 foot_texrow.newline();
4260 case LyXParagraph::MARGIN:
4263 case LyXParagraph::FIG:
4264 if (pextra_type == PEXTRA_FLOATFLT
4265 && (!pextra_width.empty()
4266 || !pextra_widthp.empty()))
4267 os << "\\end{floatingfigure}";
4269 os << "\\end{figure}";
4271 case LyXParagraph::TAB:
4272 os << "\\end{table}";
4274 case LyXParagraph::WIDE_FIG:
4275 os << "\\end{figure*}";
4277 case LyXParagraph::WIDE_TAB:
4278 os << "\\end{table*}";
4280 case LyXParagraph::ALGORITHM:
4281 os << "\\end{algorithm}";
4288 if (footnotekind != LyXParagraph::FOOTNOTE
4289 && footnotekind != LyXParagraph::MARGIN) {
4290 // we need to ensure that real floats like tables and figures
4291 // have their \end{} on a line of their own otherwise we can
4292 // get incorrect results when using the endfloat.sty package.
4297 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4302 bool LyXParagraph::IsDummy() const
4304 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4305 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4309 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4310 int type, char const * width,
4311 char const * widthp)
4314 pextra_width = width;
4315 pextra_widthp = widthp;
4317 if (textclasslist.Style(bparams.textclass,
4318 layout).isEnvironment()) {
4323 while (par && (par->layout == layout)
4324 && (par->depth == depth)) {
4326 par = par->Previous();
4329 par = par->FirstPhysicalPar();
4331 while (par && par->depth > depth) {
4332 par = par->Previous();
4335 par = par->FirstPhysicalPar();
4340 while (par && (par->layout == layout)
4341 && (par->depth == depth)) {
4342 par->pextra_type = type;
4343 par->pextra_width = width;
4344 par->pextra_widthp = widthp;
4346 par = par->NextAfterFootnote();
4350 if (par && (par->depth > depth))
4351 par->SetPExtraType(bparams,
4352 type, width, widthp);
4354 while (par && ((par->depth > depth) || par->IsDummy()))
4355 par = par->NextAfterFootnote();
4357 while (par && ((par->depth > depth)))
4365 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4367 if (pextra_type == PEXTRA_NONE)
4370 pextra_type = PEXTRA_NONE;
4371 pextra_width.erase();
4372 pextra_widthp.erase();
4374 if (textclasslist.Style(bparams.textclass,
4375 layout).isEnvironment()) {
4380 while (par && (par->layout == layout)
4381 && (par->depth == depth)) {
4383 par = par->Previous();
4386 par = par->FirstPhysicalPar();
4388 while (par && par->depth > depth) {
4389 par = par->Previous();
4392 par = par->FirstPhysicalPar();
4397 while (par && (par->layout == layout)
4398 && (par->depth == depth)) {
4399 par->pextra_type = PEXTRA_NONE;
4400 par->pextra_width.erase();
4401 par->pextra_widthp.erase();
4403 par = par->NextAfterFootnote();
4407 if (par && (par->depth > depth))
4408 par->UnsetPExtraType(bparams);
4410 while (par && ((par->depth > depth) || par->IsDummy()))
4411 par = par->NextAfterFootnote();
4413 while (par && ((par->depth > depth)))
4421 bool LyXParagraph::IsHfill(size_type pos) const
4423 return IsHfillChar(GetChar(pos));
4427 bool LyXParagraph::IsInset(size_type pos) const
4429 return IsInsetChar(GetChar(pos));
4434 bool LyXParagraph::IsFloat(size_type pos) const
4436 return IsFloatChar(GetChar(pos));
4441 bool LyXParagraph::IsNewline(size_type pos) const
4443 return pos >= 0 && IsNewlineChar(GetChar(pos));
4447 bool LyXParagraph::IsSeparator(size_type pos) const
4449 return IsSeparatorChar(GetChar(pos));
4453 bool LyXParagraph::IsLineSeparator(size_type pos) const
4455 return IsLineSeparatorChar(GetChar(pos));
4459 bool LyXParagraph::IsKomma(size_type pos) const
4461 return IsKommaChar(GetChar(pos));
4465 /// Used by the spellchecker
4466 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4468 value_type c = GetChar(pos);
4469 if (IsLetterChar(c))
4471 // '\0' is not a letter, allthough every string contains "" (below)
4474 // We want to pass the ' and escape chars to ispell
4475 string extra = lyxrc.isp_esc_chars + '\'';
4479 return contains(extra, ch);
4483 bool LyXParagraph::IsWord(size_type pos ) const
4485 return IsWordChar(GetChar(pos)) ;
4490 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4494 return FirstPhysicalPar()->getParLanguage(bparams);
4501 return GetFirstFontSettings().language();
4504 for (size_type pos = 0; pos < size(); ++pos)
4506 return GetFontSettings(bparams, pos).language();
4507 return GetFirstFontSettings().language();
4511 return previous->getParLanguage(bparams);
4513 return bparams.language_info;
4517 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4519 return lyxrc.rtl_support && !table
4520 && getParLanguage(bparams)->RightToLeft();
4524 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4525 Language const * from, Language const * to)
4527 for(size_type i = 0; i < size(); ++i) {
4528 LyXFont font = GetFontSettings(bparams, i);
4529 if (font.language() == from) {
4530 font.setLanguage(to);
4537 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4539 Language const * doc_language = bparams.language_info;
4540 for (FontList::const_iterator cit = fontlist.begin();
4541 cit != fontlist.end(); ++cit)
4542 if ((*cit).font.language() != doc_language)
4548 // Convert the paragraph to a string.
4549 // Used for building the table of contents
4550 string LyXParagraph::String(Buffer const * buffer, bool label)
4552 BufferParams const & bparams = buffer->params;
4555 if (label && !IsDummy() && !labelstring.empty())
4557 if (label && !labelstring.empty())
4559 s += labelstring + ' ';
4560 string::size_type len = s.size();
4562 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4563 value_type c = GetChar(i);
4566 else if (c == META_INSET &&
4567 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4569 std::ostringstream ost;
4570 GetInset(i)->Ascii(buffer, ost);
4573 GetInset(i)->Ascii(buffer, ost);
4576 s += subst(ost.str(),'\n',' ');
4581 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4582 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4583 s += NextAfterFootnote()->String(buffer, false);
4587 if (isRightToLeftPar(bparams))
4588 reverse(s.begin() + len,s.end());
4596 string LyXParagraph::String(Buffer const * buffer,
4597 LyXParagraph::size_type beg,
4598 LyXParagraph::size_type end)
4605 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4607 if (cell >= table->NumberOfCellsInRow(actcell))
4616 if (beg == 0 && !IsDummy() && !labelstring.empty())
4618 if (beg == 0 && !labelstring.empty())
4620 s += labelstring + ' ';
4622 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4623 value_type c = GetChar(i);
4626 else if (c == META_INSET) {
4628 std::ostringstream ost;
4629 GetInset(i)->Ascii(buffer, ost);
4632 GetInset(i)->Ascii(buffer, ost);
4636 } else if (table && IsNewlineChar(c)) {
4637 if (cell >= table->NumberOfCellsInRow(actcell)) {
4652 void LyXParagraph::SetInsetOwner(Inset *i)
4655 for (InsetList::const_iterator cit = insetlist.begin();
4656 cit != insetlist.end(); ++cit) {
4658 (*cit).inset->setOwner(i);
4663 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4666 for (InsetList::const_iterator cit = insetlist.begin();
4667 cit != insetlist.end(); ++cit) {
4669 if ((*cit).inset->IsTextInset()) {
4670 static_cast<UpdatableInset *>
4671 ((*cit).inset)->deleteLyXText(bv);
4678 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4681 for (InsetList::const_iterator cit = insetlist.begin();
4682 cit != insetlist.end(); ++cit) {
4684 if ((*cit).inset->IsTextInset()) {
4685 static_cast<UpdatableInset *>
4686 ((*cit).inset)->resizeLyXText(bv);