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 ||
139 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
144 // The beginning or the end of a footnote environment?
145 if (footflag != footnoteflag) {
146 footflag = footnoteflag;
148 os << "\n\\begin_float "
149 << string_footnotekinds[footnotekind]
152 os << "\n\\end_float ";
156 // The beginning or end of a deeper (i.e. nested) area?
159 while (depth > dth) {
160 os << "\n\\begin_deeper ";
164 while (depth < dth) {
165 os << "\n\\end_deeper ";
171 // First write the layout
173 << textclasslist.NameOfLayout(params.textclass, layout)
176 // Maybe some vertical spaces.
177 if (added_space_top.kind() != VSpace::NONE)
178 os << "\\added_space_top "
179 << added_space_top.asLyXCommand() << " ";
180 if (added_space_bottom.kind() != VSpace::NONE)
181 os << "\\added_space_bottom "
182 << added_space_bottom.asLyXCommand() << " ";
184 // Maybe the paragraph has special spacing
185 spacing.writeFile(os, true);
187 // The labelwidth string used in lists.
188 if (!labelwidthstring.empty())
189 os << "\\labelwidthstring "
190 << labelwidthstring << '\n';
192 // Lines above or below?
196 os << "\\line_bottom ";
198 // Pagebreaks above or below?
200 os << "\\pagebreak_top ";
201 if (pagebreak_bottom)
202 os << "\\pagebreak_bottom ";
204 // Start of appendix?
205 if (start_of_appendix)
206 os << "\\start_of_appendix ";
213 if (align != LYX_ALIGN_LAYOUT) {
216 case LYX_ALIGN_LEFT: h = 1; break;
217 case LYX_ALIGN_RIGHT: h = 2; break;
218 case LYX_ALIGN_CENTER: h = 3; break;
219 default: h = 0; break;
221 os << "\\align " << string_align[h] << " ";
223 if (pextra_type != PEXTRA_NONE) {
224 os << "\\pextra_type " << pextra_type;
225 if (pextra_type == PEXTRA_MINIPAGE) {
226 os << " \\pextra_alignment "
229 os << " \\pextra_hfill "
231 if (pextra_start_minipage)
232 os << " \\pextra_start_minipage "
233 << pextra_start_minipage;
235 if (!pextra_width.empty()) {
236 os << " \\pextra_width "
237 << VSpace(pextra_width).asLyXCommand();
238 } else if (!pextra_widthp.empty()) {
239 os << " \\pextra_widthp "
246 // Dummy layout. This means that a footnote ended.
247 os << "\n\\end_float ";
248 footflag = LyXParagraph::NO_FOOTNOTE;
250 lyxerr << "Why don't we have a previous?" << endl;
254 // It might be a table.
256 os << "\\LyXTable\n";
262 bibkey->Write(buf, os);
264 LyXFont font1(LyXFont::ALL_INHERIT, params.language_info);
267 for (size_type i = 0; i < size(); ++i) {
273 // Write font changes
274 LyXFont font2 = GetFontSettings(params, i);
275 if (font2 != font1) {
276 font2.lyxWriteChanges(font1, os);
281 value_type c = GetChar(i);
285 Inset const * inset = GetInset(i);
287 if (inset->DirectWrite()) {
288 // international char, let it write
289 // code directly so it's shorter in
291 inset->Write(buf, os);
293 os << "\n\\begin_inset ";
294 inset->Write(buf, os);
295 os << "\n\\end_inset \n\n";
301 os << "\n\\newline \n";
305 os << "\n\\hfill \n";
309 os << "\n\\backslash \n";
313 if (i + 1 < size() && GetChar(i + 1) == ' ') {
320 if ((column > 70 && c == ' ')
325 // this check is to amend a bug. LyX sometimes
326 // inserts '\0' this could cause problems.
330 lyxerr << "ERROR (LyXParagraph::writeFile):"
331 " NULL char in structure." << endl;
337 // now write the next paragraph
339 next->writeFile(buf, os, params, footflag, dth);
343 void LyXParagraph::validate(LaTeXFeatures & features) const
345 BufferParams const & params = features.bufferParams();
348 // this will be useful later
349 LyXLayout const & layout =
350 textclasslist.Style(params.textclass,
355 if (line_top || line_bottom)
356 features.lyxline = true;
357 if (!spacing.isDefault())
358 features.setspace = true;
361 features.layout[GetLayout()] = true;
364 Language const * doc_language = params.language_info;
366 for (FontList::const_iterator cit = fontlist.begin();
367 cit != fontlist.end(); ++cit) {
368 if ((*cit).font.noun() == LyXFont::ON) {
369 lyxerr[Debug::LATEX] << "font.noun: "
370 << (*cit).font.noun()
372 features.noun = true;
373 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
374 << (*cit).font.stateText(0)
377 switch ((*cit).font.color()) {
379 case LColor::inherit:
383 features.color = true;
384 lyxerr[Debug::LATEX] << "Color enabled. Font: "
385 << (*cit).font.stateText(0)
389 Language const * language = (*cit).font.language();
390 if (language != doc_language) {
391 features.UsedLanguages.insert(language);
392 lyxerr[Debug::LATEX] << "Found language "
393 << language->lang() << endl;
398 for (InsetList::const_iterator cit = insetlist.begin();
399 cit != insetlist.end(); ++cit) {
401 (*cit).inset->Validate(features);
404 if (table && table->IsLongTable())
405 features.longtable = true;
406 if (pextra_type == PEXTRA_INDENT)
407 features.LyXParagraphIndent = true;
408 if (pextra_type == PEXTRA_FLOATFLT)
409 features.floatflt = true;
411 if (layout.needprotect
412 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
413 features.NeedLyXFootnoteCode = true;
415 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
416 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
417 features.NeedLyXMinipageIndent = true;
418 if (table && table->NeedRotating())
419 features.rotating = true;
421 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
422 features.algorithm = true;
427 // First few functions needed for cut and paste and paragraph breaking.
428 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
429 LyXParagraph::size_type pos) const
431 minibuffer_char = GetChar(pos);
432 minibuffer_font = GetFontSettings(bparams, pos);
433 minibuffer_inset = 0;
434 if (minibuffer_char == LyXParagraph::META_INSET) {
436 minibuffer_inset = GetInset(pos)->Clone();
438 minibuffer_inset = 0;
439 minibuffer_char = ' ';
440 // This reflects what GetInset() does (ARRae)
446 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
447 LyXParagraph::size_type pos)
449 minibuffer_char = GetChar(pos);
450 minibuffer_font = GetFontSettings(bparams, pos);
451 minibuffer_inset = 0;
452 if (minibuffer_char == LyXParagraph::META_INSET) {
454 minibuffer_inset = GetInset(pos);
455 // This is a little hack since I want exactly
456 // the inset, not just a clone. Otherwise
457 // the inset would be deleted when calling Erase(pos)
459 InsetTable search_elem(pos, 0);
460 InsetList::iterator it =
461 lower_bound(insetlist.begin(),
463 search_elem, matchIT());
464 if (it != insetlist.end() && (*it).pos == pos)
467 minibuffer_inset = 0;
468 minibuffer_char = ' ';
469 // This reflects what GetInset() does (ARRae)
474 // Erase(pos); now the caller is responsible for that.
478 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
480 if ((minibuffer_char == LyXParagraph::META_INSET) &&
481 !InsertInsetAllowed(minibuffer_inset))
483 if (minibuffer_char == LyXParagraph::META_INSET)
484 InsertInset(pos, minibuffer_inset, minibuffer_font);
486 InsertChar(pos, minibuffer_char, minibuffer_font);
494 void LyXParagraph::Clear()
499 pagebreak_top = false;
500 pagebreak_bottom = false;
502 added_space_top = VSpace(VSpace::NONE);
503 added_space_bottom = VSpace(VSpace::NONE);
504 spacing.set(Spacing::Default);
506 align = LYX_ALIGN_LAYOUT;
510 pextra_type = PEXTRA_NONE;
511 pextra_width.erase();
512 pextra_widthp.erase();
513 pextra_alignment = MINIPAGE_ALIGN_TOP;
514 pextra_hfill = false;
515 pextra_start_minipage = false;
518 labelwidthstring.erase();
522 start_of_appendix = false;
526 // the destructor removes the new paragraph from the list
527 LyXParagraph::~LyXParagraph()
530 previous->next = next;
532 next->previous = previous;
534 for (InsetList::iterator it = insetlist.begin();
535 it != insetlist.end(); ++it) {
539 /* table stuff -- begin*/
541 /* table stuff -- end*/
547 //lyxerr << "LyXParagraph::paragraph_id = "
548 // << LyXParagraph::paragraph_id << endl;
552 void LyXParagraph::Erase(LyXParagraph::size_type pos)
554 // > because last is the next unused position, and you can
555 // use it if you want
558 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
559 NextAfterFootnote()->Erase(pos - text.size() - 1);
562 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
563 "position does not exist." << endl;
566 if (pos < size()) { // last is free for insertation, but should be empty
567 // if it is an inset, delete the inset entry
568 if (text[pos] == LyXParagraph::META_INSET) {
570 InsetTable search_inset(pos, 0);
571 InsetList::iterator it =
572 lower_bound(insetlist.begin(),
574 search_inset, matchIT());
575 if (it != insetlist.end() && (*it).pos == pos) {
580 text.erase(text.begin() + pos);
582 // Erase entries in the tables.
583 FontTable search_font(pos, LyXFont());
585 FontList::iterator it =
586 lower_bound(fontlist.begin(),
588 search_font, matchFT());
589 if (it != fontlist.end() && (*it).pos == pos &&
591 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
592 // If it is a multi-character font
593 // entry, we just make it smaller
594 // (see update below), otherwise we
596 unsigned int i = it - fontlist.begin();
597 fontlist.erase(fontlist.begin() + i);
598 it = fontlist.begin() + i;
599 if (i > 0 && i < fontlist.size() &&
600 fontlist[i-1].font == fontlist[i].font) {
601 fontlist.erase(fontlist.begin() + i-1);
602 it = fontlist.begin() + i-1;
606 // Update all other entries.
607 for (; it != fontlist.end(); ++it)
610 // Update the inset table.
611 InsetTable search_inset(pos, 0);
612 for (InsetList::iterator it =
613 upper_bound(insetlist.begin(),
615 search_inset, matchIT());
616 it != insetlist.end(); ++it)
619 lyxerr << "ERROR (LyXParagraph::Erase): "
620 "can't erase non-existant char." << endl;
625 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
626 LyXParagraph::value_type c)
628 LyXFont f(LyXFont::ALL_INHERIT);
629 InsertChar(pos, c, f);
633 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
634 LyXParagraph::value_type c,
635 LyXFont const & font)
637 // > because last is the next unused position, and you can
638 // use it if you want
642 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
643 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
647 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
648 "position does not exist." << endl;
651 text.insert(text.begin() + pos, c);
652 // Update the font table.
653 FontTable search_font(pos, LyXFont());
654 for (FontList::iterator it = lower_bound(fontlist.begin(),
656 search_font, matchFT());
657 it != fontlist.end(); ++it)
660 // Update the inset table.
661 InsetTable search_inset(pos, 0);
662 for (InsetList::iterator it = lower_bound(insetlist.begin(),
664 search_inset, matchIT());
665 it != insetlist.end(); ++it)
672 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
675 LyXFont f(LyXFont::ALL_INHERIT);
676 InsertInset(pos, inset, f);
680 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
681 Inset * inset, LyXFont const & font)
685 // > because last is the next unused position, and you can
686 // use it if you want
690 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
692 ->InsertInset(pos - text.size() - 1,
696 lyxerr << "ERROR (LyXParagraph::InsertInset): "
697 "position does not exist: " << pos << endl;
701 InsertChar(pos, META_INSET, font);
702 Assert(text[pos] == META_INSET);
704 // Add a new entry in the inset table.
705 InsetTable search_inset(pos, 0);
706 InsetList::iterator it = lower_bound(insetlist.begin(),
708 search_inset, matchIT());
709 if (it != insetlist.end() && (*it).pos == pos)
710 lyxerr << "ERROR (LyXParagraph::InsertInset): "
711 "there is an inset in position: " << pos << endl;
713 insetlist.insert(it, InsetTable(pos, inset));
715 inset->setOwner(inset_owner);
719 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
721 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
724 return inset_owner->InsertInsetAllowed(inset);
729 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
734 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
735 return NextAfterFootnote()
736 ->GetInset(pos - text.size() - 1);
739 lyxerr << "ERROR (LyXParagraph::GetInset): "
740 "position does not exist: "
746 InsetTable search_inset(pos, 0);
747 InsetList::iterator it = lower_bound(insetlist.begin(),
749 search_inset, matchIT());
750 if (it != insetlist.end() && (*it).pos == pos)
753 lyxerr << "ERROR (LyXParagraph::GetInset): "
754 "Inset does not exist: " << pos << endl;
757 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
758 // Did this commenting out introduce a bug? So far I have not
759 // see any, please enlighten me. (Lgb)
760 // My guess is that since the inset does not exist, we might
761 // as well replace it with a space to prevent craches. (Asger)
766 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
771 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
772 return NextAfterFootnote()
773 ->GetInset(pos - text.size() - 1);
776 lyxerr << "ERROR (LyXParagraph::GetInset): "
777 "position does not exist: "
783 InsetTable search_inset(pos, 0);
784 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
786 search_inset, matchIT());
787 if (cit != insetlist.end() && (*cit).pos == pos)
790 lyxerr << "ERROR (LyXParagraph::GetInset): "
791 "Inset does not exist: " << pos << endl;
793 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
794 // Did this commenting out introduce a bug? So far I have not
795 // see any, please enlighten me. (Lgb)
796 // My guess is that since the inset does not exist, we might
797 // as well replace it with a space to prevent craches. (Asger)
802 // Gets uninstantiated font setting at position.
803 // Optimized after profiling. (Asger)
804 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
805 LyXParagraph::size_type pos) const
808 FontTable search_font(pos, LyXFont());
809 FontList::const_iterator cit = lower_bound(fontlist.begin(),
811 search_font, matchFT());
812 if (cit != fontlist.end())
815 // > because last is the next unused position, and you can
816 // use it if you want
817 else if (pos > size()) {
820 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
821 return NextAfterFootnote()
822 ->GetFontSettings(bparams,
823 pos - text.size() - 1);
826 // Why is it an error to ask for the font of a
827 // position that does not exist? Would it be
828 // enough for this to be enabled on debug?
829 // We want strict error checking, but it's ok to only
830 // have it when debugging. (Asger)
831 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
832 "position does not exist. "
833 << pos << " (" << static_cast<int>(pos)
835 } else if (pos > 0) {
836 return GetFontSettings(bparams, pos - 1);
837 } else // pos = size() = 0
838 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
840 return LyXFont(LyXFont::ALL_INHERIT);
843 // Gets uninstantiated font setting at position 0
844 LyXFont LyXParagraph::GetFirstFontSettings() const
847 if (!fontlist.empty())
848 return fontlist[0].font;
852 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
853 return NextAfterFootnote()->GetFirstFontSettings();
855 return LyXFont(LyXFont::ALL_INHERIT);
859 // Gets the fully instantiated font at a given position in a paragraph
860 // This is basically the same function as LyXText::GetFont() in text2.C.
861 // The difference is that this one is used for generating the LaTeX file,
862 // and thus cosmetic "improvements" are disallowed: This has to deliver
863 // the true picture of the buffer. (Asger)
864 // If position is -1, we get the layout font of the paragraph.
865 // If position is -2, we get the font of the manual label of the paragraph.
866 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
867 LyXParagraph::size_type pos) const
870 LyXLayout const & layout =
871 textclasslist.Style(bparams.textclass,
873 LyXParagraph::size_type main_body = 0;
874 if (layout.labeltype == LABEL_MANUAL)
875 main_body = BeginningOfMainBody();
880 layoutfont = layout.labelfont;
882 layoutfont = layout.font;
883 tmpfont = GetFontSettings(bparams, pos);
884 tmpfont.realize(layoutfont);
886 // process layoutfont for pos == -1 and labelfont for pos < -1
888 tmpfont = layout.font;
890 tmpfont = layout.labelfont;
891 tmpfont.setLanguage(getParLanguage(bparams));
894 // check for environment font information
895 char par_depth = GetDepth();
896 LyXParagraph const * par = this;
897 while (par && par_depth && !tmpfont.resolved()) {
898 par = par->DepthHook(par_depth - 1);
900 tmpfont.realize(textclasslist.
901 Style(bparams.textclass,
902 par->GetLayout()).font);
903 par_depth = par->GetDepth();
907 tmpfont.realize(textclasslist
908 .TextClass(bparams.textclass)
914 /// Returns the height of the highest font in range
916 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
917 LyXParagraph::size_type endpos) const
919 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
920 if (fontlist.empty())
923 FontTable end_search(endpos, LyXFont());
924 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
926 end_search, matchFT());
927 if (end_it != fontlist.end())
930 FontTable start_search(startpos, LyXFont());
931 for (FontList::const_iterator cit =
932 lower_bound(fontlist.begin(),
934 start_search, matchFT());
935 cit != end_it; ++cit) {
936 LyXFont::FONT_SIZE size = (*cit).font.size();
937 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
944 LyXParagraph::value_type
945 LyXParagraph::GetChar(LyXParagraph::size_type pos)
952 // > because last is the next unused position, and you can
953 // use it if you want
954 else if (pos > size()) {
956 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
957 return NextAfterFootnote()
958 ->GetChar(pos - text.size() - 1);
962 lyxerr << "ERROR (LyXParagraph::GetChar): "
963 "position does not exist."
964 << pos << " (" << static_cast<int>(pos)
966 // Assert(false); // This triggers sometimes...
975 // We should have a footnote environment.
976 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
977 // Notice that LyX does request the
978 // last char from time to time. (Asger)
979 //lyxerr << "ERROR (LyXParagraph::GetChar): "
980 // "expected footnote." << endl;
983 switch (next->footnotekind) {
984 case LyXParagraph::FOOTNOTE:
985 return LyXParagraph::META_FOOTNOTE;
986 case LyXParagraph::MARGIN:
987 return LyXParagraph::META_MARGIN;
988 case LyXParagraph::FIG:
989 case LyXParagraph::WIDE_FIG:
990 return LyXParagraph::META_FIG;
991 case LyXParagraph::TAB:
992 case LyXParagraph::WIDE_TAB:
993 return LyXParagraph::META_TAB;
994 case LyXParagraph::ALGORITHM:
995 return LyXParagraph::META_ALGORITHM;
997 return '\0'; // to shut up gcc
1000 return '\0'; // to shut up gcc
1005 LyXParagraph::value_type
1006 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
1013 // > because last is the next unused position, and you can
1014 // use it if you want
1015 else if (pos > size()) {
1017 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1018 return NextAfterFootnote()
1019 ->GetChar(pos - text.size() - 1);
1023 lyxerr << "ERROR (LyXParagraph::GetChar const): "
1024 "position does not exist."
1025 << pos << " (" << static_cast<int>(pos)
1033 // We should have a footnote environment.
1034 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1035 // Notice that LyX does request the
1036 // last char from time to time. (Asger)
1037 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1038 // "expected footnote." << endl;
1041 switch (next->footnotekind) {
1042 case LyXParagraph::FOOTNOTE:
1043 return LyXParagraph::META_FOOTNOTE;
1044 case LyXParagraph::MARGIN:
1045 return LyXParagraph::META_MARGIN;
1046 case LyXParagraph::FIG:
1047 case LyXParagraph::WIDE_FIG:
1048 return LyXParagraph::META_FIG;
1049 case LyXParagraph::TAB:
1050 case LyXParagraph::WIDE_TAB:
1051 return LyXParagraph::META_TAB;
1052 case LyXParagraph::ALGORITHM:
1053 return LyXParagraph::META_ALGORITHM;
1055 return '\0'; // to shut up gcc
1058 return '\0'; // to shut up gcc
1064 // return an string of the current word, and the end of the word in lastpos.
1065 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1069 // the current word is defined as starting at the first character
1070 // from the immediate left of lastpospos which meets the definition
1071 // of IsLetter(), continuing to the last character to the right
1072 // of this meeting IsLetter.
1078 // move back until we have a letter
1080 //there's no real reason to have firstpos & lastpos as
1081 //separate variables as this is written, but maybe someon
1082 // will want to return firstpos in the future.
1084 //since someone might have typed a punctuation first
1085 int firstpos = lastpos;
1087 while ((firstpos >= 0) && !IsLetter(firstpos))
1090 // now find the beginning by looking for a nonletter
1092 while ((firstpos>= 0) && IsLetter(firstpos))
1095 // the above is now pointing to the preceeding non-letter
1099 // so copy characters into theword until we get a nonletter
1100 // note that this can easily exceed lastpos, wich means
1101 // that if used in the middle of a word, the whole word
1104 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1111 LyXParagraph::size_type LyXParagraph::Last() const
1114 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1115 return text.size() + NextAfterFootnote()->Last() + 1;
1116 // the 1 is the symbol
1124 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1126 // > because last is the next unused position, and you can
1127 // use it if you want
1131 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1132 return NextAfterFootnote()
1133 ->ParFromPos(pos - text.size() - 1);
1136 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1137 "position does not exist." << endl;
1144 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1146 // > because last is the next unused position, and you can
1147 // use it if you want
1151 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1152 return NextAfterFootnote()
1153 ->PositionInParFromPos(pos - text.size() - 1);
1157 "ERROR (LyXParagraph::PositionInParFromPos): "
1158 "position does not exist." << endl;
1166 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1167 LyXFont const & font)
1169 // > because last is the next unused position, and you can
1170 // use it if you want
1174 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1175 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1179 lyxerr << "ERROR (LyXParagraph::SetFont): "
1180 "position does not exist." << endl;
1185 // First, reduce font against layout/label font
1186 // Update: The SetCharFont() routine in text2.C already
1187 // reduces font, so we don't need to do that here. (Asger)
1188 // No need to simplify this because it will disappear
1189 // in a new kernel. (Asger)
1190 // Next search font table
1192 FontTable search_font(pos, LyXFont());
1193 FontList::iterator it = lower_bound(fontlist.begin(),
1195 search_font, matchFT());
1196 unsigned int i = it - fontlist.begin();
1197 bool notfound = it == fontlist.end();
1199 if (!notfound && fontlist[i].font == font)
1202 bool begin = pos == 0 || notfound ||
1203 (i > 0 && fontlist[i-1].pos == pos - 1);
1204 // Is position pos is a beginning of a font block?
1205 bool end = !notfound && fontlist[i].pos == pos;
1206 // Is position pos is the end of a font block?
1207 if (begin && end) { // A single char block
1208 if (i+1 < fontlist.size() &&
1209 fontlist[i+1].font == font) {
1210 // Merge the singleton block with the next block
1211 fontlist.erase(fontlist.begin() + i);
1212 if (i > 0 && fontlist[i-1].font == font)
1213 fontlist.erase(fontlist.begin() + i-1);
1214 } else if (i > 0 && fontlist[i-1].font == font) {
1215 // Merge the singleton block with the previous block
1216 fontlist[i-1].pos = pos;
1217 fontlist.erase(fontlist.begin() + i);
1219 fontlist[i].font = font;
1221 if (i > 0 && fontlist[i-1].font == font)
1222 fontlist[i-1].pos = pos;
1224 fontlist.insert(fontlist.begin() + i,
1225 FontTable(pos, font));
1227 fontlist[i].pos = pos - 1;
1228 if (!(i+1 < fontlist.size() &&
1229 fontlist[i+1].font == font))
1230 fontlist.insert(fontlist.begin() + i+1,
1231 FontTable(pos, font));
1232 } else { // The general case. The block is splitted into 3 blocks
1233 fontlist.insert(fontlist.begin() + i,
1234 FontTable(pos - 1, fontlist[i].font));
1235 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1240 // This function is able to hide closed footnotes.
1241 LyXParagraph * LyXParagraph::Next()
1244 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1245 LyXParagraph * tmp = next;
1247 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1249 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1250 return tmp->Next(); /* there can be more than one
1251 footnote in a logical
1254 return next; // This should never happen!
1262 LyXParagraph * LyXParagraph::NextAfterFootnote()
1264 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1265 LyXParagraph * tmp = next;
1266 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1268 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1269 return tmp; /* there can be more than one footnote
1270 in a logical paragraph */
1272 return next; // This should never happen!
1280 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1282 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1283 LyXParagraph * tmp = next;
1284 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1286 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1287 return tmp; /* there can be more than one footnote
1288 in a logical paragraph */
1290 return next; // This should never happen!
1298 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1301 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1303 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1304 tmp = tmp->previous;
1305 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1306 return tmp; /* there can be more than one footnote
1307 in a logical paragraph */
1309 return previous; // This should never happen!
1317 LyXParagraph * LyXParagraph::LastPhysicalPar()
1319 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1322 LyXParagraph * tmp = this;
1324 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1325 tmp = tmp->NextAfterFootnote();
1333 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1335 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1338 LyXParagraph const * tmp = this;
1340 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1341 tmp = tmp->NextAfterFootnote();
1349 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1353 LyXParagraph * tmppar = this;
1357 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1358 tmppar = tmppar->previous;
1369 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1373 LyXParagraph const * tmppar = this;
1377 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1378 tmppar = tmppar->previous;
1388 // This function is able to hide closed footnotes.
1389 LyXParagraph * LyXParagraph::Previous()
1392 LyXParagraph * tmp = previous;
1397 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1398 tmp = tmp->previous;
1400 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1401 tmp = tmp->previous;
1402 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1403 return tmp->next->Previous();
1413 // This function is able to hide closed footnotes.
1414 LyXParagraph const * LyXParagraph::Previous() const
1417 LyXParagraph * tmp = previous;
1421 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1422 tmp = tmp->previous;
1424 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1425 tmp = tmp->previous;
1426 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1427 return tmp->next->Previous();
1437 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1438 LyXParagraph::size_type pos,
1441 size_type i, j, pos_end, pos_first;
1442 // create a new paragraph
1443 LyXParagraph * par = ParFromPos(pos);
1445 LyXParagraph * firstpar = FirstPhysicalPar();
1447 LyXParagraph * firstpar = this;
1450 LyXParagraph * tmp = new LyXParagraph(par);
1453 tmp->footnoteflag = footnoteflag;
1454 tmp->footnotekind = footnotekind;
1456 // this is an idea for a more userfriendly layout handling, I will
1457 // see what the users say
1459 // layout stays the same with latex-environments
1461 tmp->SetOnlyLayout(bparams, firstpar->layout);
1462 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1465 if (Last() > pos || !Last() || flag == 2) {
1466 tmp->SetOnlyLayout(bparams, firstpar->layout);
1467 tmp->align = firstpar->align;
1468 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1470 tmp->line_bottom = firstpar->line_bottom;
1471 firstpar->line_bottom = false;
1472 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1473 firstpar->pagebreak_bottom = false;
1474 tmp->added_space_bottom = firstpar->added_space_bottom;
1475 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1477 tmp->depth = firstpar->depth;
1478 tmp->noindent = firstpar->noindent;
1480 // copy everything behind the break-position
1481 // to the new paragraph
1483 while (ParFromPos(pos_first) != par)
1486 pos_end = pos_first + par->text.size() - 1;
1488 for (i = j = pos; i <= pos_end; ++i) {
1489 par->CutIntoMinibuffer(bparams, i - pos_first);
1490 if (tmp->InsertFromMinibuffer(j - pos))
1493 tmp->text.resize(tmp->text.size());
1494 for (i = pos_end; i >= pos; --i)
1495 par->Erase(i - pos_first);
1497 par->text.resize(par->text.size());
1500 // just an idea of me
1502 tmp->line_top = firstpar->line_top;
1503 tmp->pagebreak_top = firstpar->pagebreak_top;
1504 tmp->added_space_top = firstpar->added_space_top;
1505 tmp->bibkey = firstpar->bibkey;
1507 // layout stays the same with latex-environments
1509 firstpar->SetOnlyLayout(bparams, tmp->layout);
1510 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1511 firstpar->depth = tmp->depth;
1517 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1520 par = par->FirstPhysicalPar();
1521 footnoteflag = par->footnoteflag;
1522 footnotekind = par->footnotekind;
1524 layout = par->layout;
1525 align = par-> align;
1526 SetLabelWidthString(par->labelwidthstring);
1528 line_bottom = par->line_bottom;
1529 pagebreak_bottom = par->pagebreak_bottom;
1530 added_space_bottom = par->added_space_bottom;
1532 line_top = par->line_top;
1533 pagebreak_top = par->pagebreak_top;
1534 added_space_top = par->added_space_top;
1536 spacing = par->spacing;
1538 pextra_type = par->pextra_type;
1539 pextra_width = par->pextra_width;
1540 pextra_widthp = par->pextra_widthp;
1541 pextra_alignment = par->pextra_alignment;
1542 pextra_hfill = par->pextra_hfill;
1543 pextra_start_minipage = par->pextra_start_minipage;
1545 noindent = par->noindent;
1551 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1553 LyXParagraph * tmppar = this;
1556 && tmppar->previous->footnoteflag ==
1557 LyXParagraph::CLOSED_FOOTNOTE)
1558 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1559 tmppar = tmppar->previous;
1562 return this; // This should never happen!
1569 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1571 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1581 && (IsNewline(0) || IsLineSeparator(0))){
1590 LyXParagraph * LyXParagraph::Clone() const
1592 // create a new paragraph
1593 LyXParagraph * result = new LyXParagraph;
1595 result->MakeSameLayout(this);
1597 // this is because of the dummy layout of the paragraphs that
1599 result->layout = layout;
1602 /* table stuff -- begin*/
1604 result->table = table->Clone();
1607 /* table stuff -- end*/
1609 result->inset_owner = inset_owner;
1612 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1615 // copy everything behind the break-position to the new paragraph
1617 result->text = text;
1618 result->fontlist = fontlist;
1619 result->insetlist = insetlist;
1620 for (InsetList::iterator it = result->insetlist.begin();
1621 it != result->insetlist.end(); ++it)
1622 (*it).inset = (*it).inset->Clone();
1627 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1630 par = par->FirstPhysicalPar();
1635 par->footnoteflag == footnoteflag &&
1636 par->footnotekind == footnotekind &&
1638 par->layout == layout &&
1640 par->align == align &&
1642 par->line_bottom == line_bottom &&
1643 par->pagebreak_bottom == pagebreak_bottom &&
1644 par->added_space_bottom == added_space_bottom &&
1646 par->line_top == line_top &&
1647 par->pagebreak_top == pagebreak_top &&
1648 par->added_space_top == added_space_top &&
1650 par->spacing == spacing &&
1652 par->pextra_type == pextra_type &&
1653 par->pextra_width == pextra_width &&
1654 par->pextra_widthp == pextra_widthp &&
1655 par->pextra_alignment == pextra_alignment &&
1656 par->pextra_hfill == pextra_hfill &&
1657 par->pextra_start_minipage == pextra_start_minipage &&
1659 par->table == table && // what means: NO TABLE AT ALL
1662 par->noindent == noindent &&
1663 par->depth == depth);
1667 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1668 LyXParagraph::size_type pos)
1670 // create a new paragraph
1671 LyXParagraph * par = ParFromPos(pos);
1673 LyXParagraph * tmp = new LyXParagraph(par);
1675 tmp->MakeSameLayout(par);
1677 // When can pos < Last()?
1678 // I guess pos == Last() is possible.
1680 // copy everything behind the break-position to the new
1682 size_type pos_first = 0;
1683 while (ParFromPos(pos_first) != par)
1685 size_type pos_end = pos_first + par->text.size() - 1;
1688 for (i = j = pos; i <= pos_end; ++i) {
1689 par->CutIntoMinibuffer(bparams, i - pos_first);
1690 if (tmp->InsertFromMinibuffer(j - pos))
1693 tmp->text.resize(tmp->text.size());
1694 for (size_type i = pos_end; i >= pos; --i)
1695 par->Erase(i - pos_first);
1697 par->text.resize(par->text.size());
1702 // Be carefull, this does not make any check at all.
1703 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1705 // copy the next paragraph to this one
1706 LyXParagraph * the_next = Next();
1708 LyXParagraph * firstpar = FirstPhysicalPar();
1710 LyXParagraph * firstpar = this;
1713 // first the DTP-stuff
1714 firstpar->line_bottom = the_next->line_bottom;
1715 firstpar->added_space_bottom = the_next->added_space_bottom;
1716 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1718 size_type pos_end = the_next->text.size() - 1;
1719 size_type pos_insert = Last();
1721 // ok, now copy the paragraph
1723 for (i = j = 0; i <= pos_end; ++i) {
1724 the_next->CutIntoMinibuffer(bparams, i);
1725 if (InsertFromMinibuffer(pos_insert + j))
1729 // delete the next paragraph
1730 LyXParagraph * ppar = the_next->previous;
1731 LyXParagraph * npar = the_next->next;
1738 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1740 LyXParagraph * par = ParFromPos(pos);
1742 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1743 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1749 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1751 LyXParagraph * par = ParFromPos(pos);
1753 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1754 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1761 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1763 LyXParagraph const * par = this;
1764 int par_depth = GetDepth();
1766 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1768 textclasslist.Style(bparams.textclass,
1769 layout).endlabeltype;
1770 if (endlabeltype != END_LABEL_NO_LABEL) {
1771 LyXParagraph const * last = this;
1773 if( footnoteflag == NO_FOOTNOTE)
1774 last = LastPhysicalPar();
1775 else if (next->footnoteflag == NO_FOOTNOTE)
1776 return endlabeltype;
1781 if (!last || !last->next)
1782 return endlabeltype;
1784 int next_depth = last->next->GetDepth();
1785 if (par_depth > next_depth ||
1786 (par_depth == next_depth && layout != last->next->GetLayout() ))
1787 return endlabeltype;
1792 par = par->DepthHook(par_depth - 1);
1794 par_depth = par->GetDepth();
1796 return END_LABEL_NO_LABEL;
1800 LyXTextClass::size_type LyXParagraph::GetLayout() const
1803 return FirstPhysicalPar()->layout;
1810 char LyXParagraph::GetDepth() const
1813 return FirstPhysicalPar()->depth;
1820 char LyXParagraph::GetAlign() const
1823 return FirstPhysicalPar()->align;
1830 string const & LyXParagraph::GetLabelstring() const
1833 return FirstPhysicalPar()->labelstring;
1840 int LyXParagraph::GetFirstCounter(int i) const
1843 return FirstPhysicalPar()->counter_[i];
1850 // the next two functions are for the manual labels
1851 string LyXParagraph::GetLabelWidthString() const
1854 if (!FirstPhysicalPar()->labelwidthstring.empty())
1855 return FirstPhysicalPar()->labelwidthstring;
1857 if (!labelwidthstring.empty())
1858 return labelwidthstring;
1861 return _("Senseless with this layout!");
1865 void LyXParagraph::SetLabelWidthString(string const & s)
1868 LyXParagraph * par = FirstPhysicalPar();
1870 par->labelwidthstring = s;
1872 labelwidthstring = s;
1877 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1878 LyXTextClass::size_type new_layout)
1881 LyXParagraph * par = FirstPhysicalPar();
1883 LyXParagraph * par = this;
1885 LyXParagraph * ppar = 0;
1886 LyXParagraph * npar = 0;
1888 par->layout = new_layout;
1890 /* table stuff -- begin*/
1893 /* table stuff -- end*/
1895 if (par->pextra_type == PEXTRA_NONE) {
1896 if (par->Previous()) {
1898 ppar = par->Previous()->FirstPhysicalPar();
1900 ppar = par->Previous();
1904 && (ppar->depth > par->depth))
1906 ppar = ppar->Previous()->FirstPhysicalPar();
1908 ppar = ppar->Previous();
1913 npar = par->Next()->NextAfterFootnote();
1919 && (npar->depth > par->depth))
1921 npar = npar->Next()->NextAfterFootnote();
1923 npar = npar->Next();
1926 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1928 p1 = ppar->pextra_width,
1929 p2 = ppar->pextra_widthp;
1930 ppar->SetPExtraType(bparams, ppar->pextra_type,
1931 p1.c_str(), p2.c_str());
1933 if ((par->pextra_type == PEXTRA_NONE) &&
1934 npar && (npar->pextra_type != PEXTRA_NONE)) {
1936 p1 = npar->pextra_width,
1937 p2 = npar->pextra_widthp;
1938 npar->SetPExtraType(bparams, npar->pextra_type,
1939 p1.c_str(), p2.c_str());
1945 void LyXParagraph::SetLayout(BufferParams const & bparams,
1946 LyXTextClass::size_type new_layout)
1950 * par = FirstPhysicalPar(),
1957 par->layout = new_layout;
1958 par->labelwidthstring.erase();
1959 par->align = LYX_ALIGN_LAYOUT;
1960 par->added_space_top = VSpace(VSpace::NONE);
1961 par->added_space_bottom = VSpace(VSpace::NONE);
1962 par->spacing.set(Spacing::Default);
1965 /* table stuff -- begin*/
1968 /* table stuff -- end*/
1970 if (par->pextra_type == PEXTRA_NONE) {
1971 if (par->Previous()) {
1973 ppar = par->Previous()->FirstPhysicalPar();
1975 ppar = par->Previous();
1979 && (ppar->depth > par->depth))
1981 ppar = ppar->Previous()->FirstPhysicalPar();
1983 ppar = ppar->Previous();
1988 npar = par->Next()->NextAfterFootnote();
1994 && (npar->depth > par->depth))
1996 npar = npar->Next()->NextAfterFootnote();
1998 npar = npar->Next();
2001 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2003 p1 = ppar->pextra_width,
2004 p2 = ppar->pextra_widthp;
2005 ppar->SetPExtraType(bparams, ppar->pextra_type,
2006 p1.c_str(), p2.c_str());
2008 if ((par->pextra_type == PEXTRA_NONE) &&
2009 npar && (npar->pextra_type != PEXTRA_NONE)) {
2011 p1 = npar->pextra_width,
2012 p2 = npar->pextra_widthp;
2013 npar->SetPExtraType(bparams, npar->pextra_type,
2014 p1.c_str(), p2.c_str());
2020 // if the layout of a paragraph contains a manual label, the beginning of the
2021 // main body is the beginning of the second word. This is what the par-
2022 // function returns. If the layout does not contain a label, the main
2023 // body always starts with position 0. This differentiation is necessary,
2024 // because there cannot be a newline or a blank <= the beginning of the
2025 // main body in TeX.
2027 int LyXParagraph::BeginningOfMainBody() const
2030 if (FirstPhysicalPar() != this)
2033 // Unroll the first two cycles of the loop
2034 // and remember the previous character to
2035 // remove unnecessary GetChar() calls
2038 && GetChar(i) != LyXParagraph::META_NEWLINE
2041 char previous_char = 0, temp = 0;
2043 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2044 // Yes, this ^ is supposed to be "= " not "=="
2047 && previous_char != ' '
2048 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2050 previous_char = temp;
2056 if (i == 0 && i == size() &&
2057 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2058 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2059 ++i; /* the cursor should not jump
2060 * to the main body if there
2067 LyXParagraph * LyXParagraph::DepthHook(int deth)
2069 LyXParagraph * newpar = this;
2075 newpar = newpar->FirstPhysicalPar()->Previous();
2077 newpar = newpar->Previous();
2079 } while (newpar && newpar->GetDepth() > deth
2081 && newpar->footnoteflag == footnoteflag
2086 if (Previous() || GetDepth())
2087 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2092 return newpar->FirstPhysicalPar();
2099 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2101 LyXParagraph const * newpar = this;
2107 newpar = newpar->FirstPhysicalPar()->Previous();
2109 newpar = newpar->Previous();
2111 } while (newpar && newpar->GetDepth() > deth
2113 && newpar->footnoteflag == footnoteflag
2118 if (Previous() || GetDepth())
2119 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2124 return newpar->FirstPhysicalPar();
2131 int LyXParagraph::AutoDeleteInsets()
2134 InsetList::size_type index = 0;
2135 while (index < insetlist.size()) {
2136 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2137 Erase(insetlist[index].pos);
2138 // Erase() calls to insetlist.erase(&insetlist[index])
2139 // so index shouldn't be increased.
2148 LyXParagraph::inset_iterator
2149 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2151 InsetTable search_inset(pos, 0);
2152 InsetList::iterator it = lower_bound(insetlist.begin(),
2154 search_inset, matchIT());
2155 return inset_iterator(it);
2159 // returns -1 if inset not found
2160 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2163 // We could use lower_bound here too, we just need to add
2164 // the approp. operator() to matchIT (and change the name
2165 // of that struct). Code would then be:
2166 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2168 // inset, matchIT());
2169 // if ((*cit).inset == inset) {
2170 // return (*cit).pos;
2172 for (InsetList::const_iterator cit = insetlist.begin();
2173 cit != insetlist.end(); ++cit) {
2174 if ((*cit).inset == inset) {
2179 // Think about footnotes.
2180 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2181 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2183 NextAfterFootnote()->GetPositionOfInset(inset);
2185 return text.size() + 1 + further;
2192 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2193 BufferParams const & bparams,
2194 ostream & os, TexRow & texrow,
2199 TexRow & foot_texrow,
2204 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2205 LyXLayout const & style =
2206 textclasslist.Style(bparams.textclass,
2209 bool further_blank_line = false;
2212 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2215 if (start_of_appendix) {
2216 os << "\\appendix\n";
2220 if (!spacing.isDefault()
2221 && (!Previous() || !Previous()->HasSameLayout(this))) {
2222 os << spacing.writeEnvirBegin() << "\n";
2226 if (tex_code_break_column && style.isCommand()){
2231 if (pagebreak_top) {
2233 further_blank_line = true;
2235 if (added_space_top.kind() != VSpace::NONE) {
2236 os << added_space_top.asLatexCommand(bparams);
2237 further_blank_line = true;
2241 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2242 << "\\vspace{-1\\parskip}";
2243 further_blank_line = true;
2246 if (further_blank_line){
2251 Language const * language = getParLanguage(bparams);
2252 Language const * doc_language = bparams.language_info;
2253 Language const * previous_language = previous
2254 ? previous->getParLanguage(bparams) : doc_language;
2255 if (language != doc_language && language != previous_language) {
2256 os << subst(lyxrc.language_command_begin, "$$lang",
2262 if (bparams.inputenc == "auto" &&
2263 language->encoding() != previous_language->encoding()) {
2264 os << "\\inputencoding{"
2265 << language->encoding()->LatexName()
2270 switch (style.latextype) {
2273 << style.latexname()
2274 << style.latexparam();
2276 case LATEX_ITEM_ENVIRONMENT:
2278 bibkey->Latex(buf, os, false, false);
2282 case LATEX_LIST_ENVIRONMENT:
2289 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2291 LyXParagraph * par = next;
2293 // Spit out footnotes
2294 if (lyxrc.rtl_support) {
2295 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2296 && next->footnoteflag != footnoteflag) {
2297 LyXParagraph * p = 0;
2298 bool is_rtl = (size() > 0)
2299 ? GetFontSettings(bparams,
2300 size()-1).isRightToLeft()
2301 : language->RightToLeft();
2302 if ( (p = NextAfterFootnote()) != 0 &&
2304 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2305 is_rtl = getParLanguage(bparams)->RightToLeft();
2306 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2307 && par->footnoteflag != footnoteflag) {
2308 par = par->TeXFootnote(buf, bparams,
2310 foot_texrow, foot_count,
2312 par->SimpleTeXOnePar(buf, bparams,
2313 os, texrow, moving_arg);
2314 is_rtl = (par->size() > 0)
2315 ? par->GetFontSettings(bparams,
2316 par->size()-1).isRightToLeft()
2317 : language->RightToLeft();
2319 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2320 (p = par->NextAfterFootnote()) != 0 &&
2322 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2323 is_rtl = language->RightToLeft();
2328 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2329 && par->footnoteflag != footnoteflag) {
2330 par = par->TeXFootnote(buf, bparams,
2332 foot, foot_texrow, foot_count,
2334 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2340 // Make sure that \\par is done with the font of the last
2341 // character if this has another size as the default.
2342 // This is necessary because LaTeX (and LyX on the screen)
2343 // calculates the space between the baselines according
2344 // to this font. (Matthias)
2345 LyXFont font = getFont(bparams, Last() - 1);
2347 if (style.resfont.size() != font.size()) {
2353 } else if (textclasslist.Style(bparams.textclass,
2354 GetLayout()).isCommand()) {
2355 if (style.resfont.size() != font.size()) {
2361 } else if (style.resfont.size() != font.size()){
2362 os << "{\\" << font.latexSize() << " \\par}";
2365 if (language != doc_language &&
2368 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2370 || par->getParLanguage(bparams) != language)) {
2372 << subst(lyxrc.language_command_end, "$$lang",
2373 doc_language->lang());
2376 switch (style.latextype) {
2377 case LATEX_ITEM_ENVIRONMENT:
2378 case LATEX_LIST_ENVIRONMENT:
2379 if (par && (depth < par->depth)) {
2384 case LATEX_ENVIRONMENT:
2385 // if its the last paragraph of the current environment
2386 // skip it otherwise fall through
2388 && (par->layout != layout
2389 || par->depth != depth
2390 || par->pextra_type != pextra_type))
2393 // we don't need it for the last paragraph!!!
2397 footnoteflag != LyXParagraph::NO_FOOTNOTE
2398 && footnotekind != LyXParagraph::FOOTNOTE
2399 && footnotekind != LyXParagraph::MARGIN &&
2404 // don't insert this if we would be adding it
2405 // before or after a table in a float. This
2406 // little trick is needed in order to allow
2407 // use of tables in \subfigures or \subtables.
2413 further_blank_line = false;
2415 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2416 further_blank_line = true;
2419 if (added_space_bottom.kind() != VSpace::NONE) {
2420 os << added_space_bottom.asLatexCommand(bparams);
2421 further_blank_line = true;
2424 if (pagebreak_bottom) {
2426 further_blank_line = true;
2429 if (further_blank_line){
2434 if (!spacing.isDefault()
2435 && (!par || !par->HasSameLayout(this))) {
2436 os << spacing.writeEnvirEnd() << "\n";
2440 // we don't need it for the last paragraph!!!
2443 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2444 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2451 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2456 // This one spits out the text of the paragraph
2457 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2458 BufferParams const & bparams,
2459 ostream & os, TexRow & texrow,
2462 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2466 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2469 bool return_value = false;
2471 LyXLayout const & style =
2472 textclasslist.Style(bparams.textclass,
2474 LyXFont basefont, last_font;
2476 // Maybe we have to create a optional argument.
2477 size_type main_body;
2478 if (style.labeltype != LABEL_MANUAL)
2481 main_body = BeginningOfMainBody();
2483 if (main_body > 0) {
2485 basefont = getFont(bparams, -2); // Get label font
2487 basefont = getFont(bparams, -1); // Get layout font
2498 if (style.isCommand()) {
2501 } else if (align != LYX_ALIGN_LAYOUT) {
2504 return_value = true;
2508 moving_arg |= style.needprotect;
2510 // Which font is currently active?
2511 LyXFont running_font(basefont);
2512 // Do we have an open font change?
2513 bool open_font = false;
2515 texrow.start(this, 0);
2517 for (size_type i = 0; i < size(); ++i) {
2519 // First char in paragraph or after label?
2525 if (main_body > 0) {
2527 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2530 basefont = getFont(bparams, -1); // Now use the layout font
2531 running_font = basefont;
2535 if (style.isCommand()) {
2538 } else if (align != LYX_ALIGN_LAYOUT) {
2541 return_value = true;
2545 os << "\\noindent ";
2549 case LYX_ALIGN_NONE:
2550 case LYX_ALIGN_BLOCK:
2551 case LYX_ALIGN_LAYOUT:
2552 case LYX_ALIGN_SPECIAL:
2554 case LYX_ALIGN_LEFT:
2555 if (getParLanguage(bparams)->lang() != "hebrew") {
2556 os << "\\raggedright ";
2559 os << "\\raggedleft ";
2563 case LYX_ALIGN_RIGHT:
2564 if (getParLanguage(bparams)->lang() != "hebrew") {
2565 os << "\\raggedleft ";
2568 os << "\\raggedright ";
2572 case LYX_ALIGN_CENTER:
2573 os << "\\centering ";
2579 value_type c = GetChar(i);
2581 // Fully instantiated font
2582 LyXFont font = getFont(bparams, i);
2583 LyXParagraph * p = 0;
2587 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2588 (p = PreviousBeforeFootnote()) != 0)
2592 last_font = p->getFont(bparams, p->size() - 1);
2594 last_font = running_font;
2596 // Spaces at end of font change are simulated to be
2597 // outside font change, i.e. we write "\textXX{text} "
2598 // rather than "\textXX{text }". (Asger)
2599 if (open_font && c == ' ' && i <= size() - 2
2600 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2601 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2602 font = getFont(bparams, i + 1);
2604 // We end font definition before blanks
2605 if (!font.equalExceptLatex(running_font) && open_font) {
2606 column += running_font.latexWriteEndChanges(os,
2608 (i == main_body-1) ? basefont : font);
2609 running_font = basefont;
2613 // Blanks are printed before start of fontswitch
2615 // Do not print the separation of the optional argument
2616 if (i != main_body - 1) {
2617 SimpleTeXBlanks(os, texrow, i,
2618 column, font, style);
2622 // Do we need to change font?
2623 if (!font.equalExceptLatex(running_font)
2624 && i != main_body-1) {
2625 column += font.latexWriteStartChanges(os, basefont,
2627 running_font = font;
2631 if (c == LyXParagraph::META_NEWLINE) {
2632 // newlines are handled differently here than
2633 // the default in SimpleTeXSpecialChars().
2634 if (!style.newline_allowed
2635 || font.latex() == LyXFont::ON) {
2639 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2642 basefont = getFont(bparams, -1);
2643 running_font = basefont;
2644 if (font.family() ==
2645 LyXFont::TYPEWRITER_FAMILY) {
2653 texrow.start(this, i + 1);
2656 SimpleTeXSpecialChars(buf, bparams,
2657 os, texrow, moving_arg,
2658 font, running_font, basefont,
2659 open_font, style, i, column, c);
2663 // If we have an open font definition, we have to close it
2665 LyXParagraph * p = 0;
2668 && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2669 && (p = NextAfterFootnote()) != 0
2674 running_font.latexWriteEndChanges(os, basefont,
2675 p->getFont(bparams, 0));
2677 running_font.latexWriteEndChanges(os, basefont, basefont);
2680 // Needed if there is an optional argument but no contents.
2681 if (main_body > 0 && main_body == size()) {
2683 return_value = false;
2686 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2687 return return_value;
2691 // This one spits out the text of a table paragraph
2692 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2693 BufferParams const & bparams,
2694 ostream & os, TexRow & texrow)
2696 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2698 bool return_value = false;
2700 LyXLayout const & style =
2701 textclasslist.Style(bparams.textclass, GetLayout());
2705 if (!IsDummy()) { // it is dummy if it is in a float!!!
2707 if (style.isCommand()) {
2710 } else if (align != LYX_ALIGN_LAYOUT) {
2713 return_value = true;
2716 os << "\\noindent ";
2720 case LYX_ALIGN_NONE:
2721 case LYX_ALIGN_BLOCK:
2722 case LYX_ALIGN_LAYOUT:
2723 case LYX_ALIGN_SPECIAL: break;
2724 case LYX_ALIGN_LEFT:
2725 os << "\\raggedright ";
2728 case LYX_ALIGN_RIGHT:
2729 os << "\\raggedleft ";
2732 case LYX_ALIGN_CENTER:
2733 os << "\\centering ";
2741 LyXFont basefont = getFont(bparams, -1); // Get layout font
2742 // Which font is currently active?
2743 LyXFont running_font = basefont;
2745 // Do we have an open font change?
2746 bool open_font = false;
2747 int current_cell_number = -1;
2748 int tmp = table->TexEndOfCell(os, current_cell_number);
2749 for (; tmp > 0 ; --tmp)
2752 texrow.start(this, 0);
2754 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2755 bool first_in_cell = true;
2757 for (size_type i = 0; i < size(); ++i) {
2758 value_type c = GetChar(i);
2759 if (table->IsContRow(current_cell_number + 1)) {
2760 if (c == LyXParagraph::META_NEWLINE)
2761 ++current_cell_number;
2766 if (first_in_cell && is_rtl) {
2769 first_in_cell = false;
2772 // Fully instantiated font
2773 LyXFont font = getFont(bparams, i);
2774 last_font = running_font;
2776 // Spaces at end of font change are simulated to be
2777 // outside font change.
2778 // i.e. we write "\textXX{text} " rather than
2779 // "\textXX{text }". (Asger)
2780 if (open_font && c == ' ' && i <= size() - 2
2781 && getFont(bparams, i + 1) != running_font
2782 && getFont(bparams, i + 1) != font) {
2783 font = getFont(bparams, i + 1);
2786 // We end font definition before blanks
2787 if (font != running_font && open_font) {
2788 column += running_font.latexWriteEndChanges(os,
2791 running_font = basefont;
2794 // Blanks are printed before start of fontswitch
2796 SimpleTeXBlanks(os, texrow, i, column, font, style);
2798 // Do we need to change font?
2799 if (font != running_font) {
2800 column += font.latexWriteStartChanges(os, basefont,
2802 running_font = font;
2805 // Do we need to turn on LaTeX mode?
2806 if (font.latex() != running_font.latex()) {
2807 if (font.latex() == LyXFont::ON
2808 && style.needprotect) {
2813 if (c == LyXParagraph::META_NEWLINE) {
2814 // special case for inside a table
2815 // different from default case in
2816 // SimpleTeXSpecialChars()
2818 column += running_font
2819 .latexWriteEndChanges(os, basefont,
2823 basefont = getFont(bparams, -1);
2824 running_font = basefont;
2825 ++current_cell_number;
2826 if (table->CellHasContRow(current_cell_number) >= 0) {
2827 TeXContTableRows(buf, bparams, os, i + 1,
2828 current_cell_number,
2831 if (is_rtl && !first_in_cell) {
2833 first_in_cell = true;
2836 // if this cell follow only ContRows till end don't
2837 // put the EndOfCell because it is put after the
2839 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2840 --current_cell_number;
2843 int tmp = table->TexEndOfCell(os,
2844 current_cell_number);
2847 } else if (tmp < 0) {
2853 texrow.start(this, i + 1);
2855 SimpleTeXSpecialChars(buf, bparams,
2857 font, running_font, basefont,
2858 open_font, style, i, column, c);
2862 // If we have an open font definition, we have to close it
2864 running_font.latexWriteEndChanges(os, basefont, basefont);
2866 ++current_cell_number;
2867 if (is_rtl && !first_in_cell)
2869 tmp = table->TexEndOfCell(os, current_cell_number);
2870 for (; tmp > 0; --tmp)
2872 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2873 return return_value;
2877 // This one spits out the text off ContRows in tables
2878 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2879 BufferParams const & bparams,
2881 LyXParagraph::size_type i,
2882 int current_cell_number,
2883 int & column, TexRow & texrow)
2885 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2889 bool return_value = false;
2890 LyXLayout const & style =
2891 textclasslist.Style(bparams.textclass,
2893 LyXFont basefont = getFont(bparams, -1); // Get layout font
2895 // Which font is currently active?
2896 LyXFont running_font = basefont;
2897 // Do we have an open font change?
2898 bool open_font = false;
2900 size_type lastpos = i;
2901 int cell = table->CellHasContRow(current_cell_number);
2902 ++current_cell_number;
2905 // first find the right position
2907 for (; (i < size()) && (current_cell_number < cell); ++i) {
2909 if (c == LyXParagraph::META_NEWLINE)
2910 ++current_cell_number;
2914 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2918 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2923 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2927 // Fully instantiated font
2928 LyXFont font = getFont(bparams, i);
2929 last_font = running_font;
2931 // Spaces at end of font change are simulated to
2932 // be outside font change. i.e. we write
2933 // "\textXX{text} " rather than "\textXX{text }".
2935 if (open_font && c == ' ' && i <= size() - 2
2936 && getFont(bparams, i + 1) != running_font
2937 && getFont(bparams, i + 1) != font) {
2938 font = getFont(bparams, i + 1);
2941 // We end font definition before blanks
2942 if (font != running_font && open_font) {
2943 column += running_font.latexWriteEndChanges(os, basefont, font);
2944 running_font = basefont;
2947 // Blanks are printed before start of fontswitch
2949 SimpleTeXBlanks(os, texrow, i,
2950 column, font, style);
2952 // Do we need to change font?
2953 if (font != running_font) {
2955 font.latexWriteStartChanges(os,
2958 running_font = font;
2961 // Do we need to turn on LaTeX mode?
2962 if (font.latex() != running_font.latex()) {
2963 if (font.latex() == LyXFont::ON
2964 && style.needprotect) {
2969 SimpleTeXSpecialChars(buf, bparams,
2970 os, texrow, false, font,
2971 running_font, basefont,
2972 open_font, style, i, column, c);
2974 // If we have an open font definition, we have to close it
2976 running_font.latexWriteEndChanges(os, basefont,
2980 basefont = getFont(bparams, -1);
2981 running_font = basefont;
2982 cell = table->CellHasContRow(current_cell_number);
2984 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2985 return return_value;
2989 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2991 bool retval = false;
2993 case LyXParagraph::META_HFILL:
2994 sgml_string.erase();
2996 case LyXParagraph::META_NEWLINE:
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 = "˜";
3033 sgml_string = """;
3036 sgml_string = "\";
3042 case '\0': // Ignore :-)
3043 sgml_string.erase();
3053 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
3054 ostream & os, string & extra,
3055 int & desc_on, int depth)
3057 BufferParams const & bparams = buffer->params;
3059 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
3061 LyXFont font1, font2;
3064 size_type main_body;
3065 bool emph_flag = false;
3067 LyXLayout const & style =
3068 textclasslist.Style(bparams.textclass,
3071 if (style.labeltype != LABEL_MANUAL)
3074 main_body = BeginningOfMainBody();
3076 // Gets paragraph main font.
3078 font1 = style.labelfont;
3082 int char_line_count = depth;
3083 os << newlineAndDepth(depth);
3085 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3086 os << "<INFORMALTABLE>"
3087 << newlineAndDepth(++depth);
3090 os << "<INFORMALTABLE>"
3091 << newlineAndDepth(++depth);
3093 int current_cell_number = -1;
3094 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3096 // Parsing main loop.
3097 for (size_type i = 0; i < size(); ++i) {
3099 if (table->IsContRow(current_cell_number+1)) {
3100 if (c == LyXParagraph::META_NEWLINE)
3101 ++current_cell_number;
3106 // Fully instantiated font
3107 font2 = getFont(bparams, i);
3109 // Handle <emphasis> tag.
3110 if (font1.emph() != font2.emph() && i) {
3111 if (font2.emph() == LyXFont::ON) {
3114 } else if (emph_flag) {
3115 os << "</emphasis>";
3119 if (c == LyXParagraph::META_NEWLINE) {
3120 // We have only to control for emphasis open here!
3122 os << "</emphasis>";
3125 font1 = font2 = getFont(bparams, -1);
3126 ++current_cell_number;
3127 if (table->CellHasContRow(current_cell_number) >= 0) {
3128 DocBookContTableRows(buffer,
3129 os, extra, desc_on, i + 1,
3130 current_cell_number,
3133 // if this cell follow only ContRows till end don't
3134 // put the EndOfCell because it is put after the
3136 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3137 --current_cell_number;
3140 tmp = table->DocBookEndOfCell(os,
3141 current_cell_number,
3146 } else if (c == LyXParagraph::META_INSET) {
3147 inset = GetInset(i);
3149 std::ostringstream ost;
3150 inset->DocBook(buffer, ost);
3151 string tmp_out = ost.str().c_str();
3154 inset->DocBook(buffer, ost);
3156 char * ctmp = ost.str();
3157 string tmp_out(ctmp);
3161 // This code needs some explanation:
3162 // Two insets are treated specially
3163 // label if it is the first element in a
3164 // command paragraph
3166 // graphics inside tables or figure floats
3168 // title (the equivalente in latex for this
3170 // and title should come first
3173 if(desc_on != 3 || i != 0) {
3174 if(tmp_out[0] == '@') {
3176 extra += frontStrip(tmp_out,
3179 os << frontStrip(tmp_out,
3184 } else if (font2.latex() == LyXFont::ON) {
3185 // "TeX"-Mode on == > SGML-Mode on.
3191 if (linuxDocConvertChar(c, sgml_string)
3192 && !style.free_spacing) {
3193 // in freespacing mode, spaces are
3194 // non-breaking characters
3199 << "</term><listitem><para>";
3211 // Needed if there is an optional argument but no contents.
3212 if (main_body > 0 && main_body == size()) {
3217 os << "</emphasis>";
3220 ++current_cell_number;
3221 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3222 // Resets description flag correctly.
3225 // <term> not closed...
3230 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3232 os << "</INFORMALTABLE>";
3234 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3239 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3240 ostream & os, string & extra,
3242 LyXParagraph::size_type i,
3243 int current_cell_number, int &column)
3248 BufferParams const & bparams = buffer->params;
3250 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3255 //string emph = "emphasis";
3256 bool emph_flag = false;
3257 int char_line_count = 0;
3259 LyXLayout const & style =
3260 textclasslist.Style(bparams.textclass,
3263 size_type main_body;
3264 if (style.labeltype != LABEL_MANUAL)
3267 main_body = BeginningOfMainBody();
3269 // Gets paragraph main font.
3272 font1 = style.labelfont;
3276 size_type lastpos = i;
3277 int cell = table->CellHasContRow(current_cell_number);
3278 ++current_cell_number;
3280 // first find the right position
3282 for (; i < size() && current_cell_number < cell; ++i) {
3284 if (c == LyXParagraph::META_NEWLINE)
3285 ++current_cell_number;
3289 // I don't know how to handle this so I comment it
3290 // for the moment (Jug)
3291 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3292 // file += " \\\\\n";
3295 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3300 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3304 // Fully instantiated font
3305 font2 = getFont(bparams, i);
3307 // Handle <emphasis> tag.
3308 if (font1.emph() != font2.emph() && i) {
3309 if (font2.emph() == LyXFont::ON) {
3312 } else if (emph_flag) {
3313 os << "</emphasis>";
3317 if (c == LyXParagraph::META_INSET) {
3318 inset = GetInset(i);
3320 std::ostringstream ost;
3321 inset->DocBook(buffer, ost);
3322 string tmp_out = ost.str().c_str();
3325 inset->DocBook(buffer, ost);
3327 char * ctmp = ost.str();
3328 string tmp_out(ctmp);
3332 // This code needs some explanation:
3333 // Two insets are treated specially
3334 // label if it is the first element in a
3335 // command paragraph
3337 // graphics inside tables or figure floats
3338 // can't go on title (the equivalente in
3339 // latex for this case is caption and title
3340 // should come first
3343 if(desc_on != 3 || i != 0) {
3344 if(tmp_out[0] == '@') {
3346 extra += frontStrip(tmp_out, '@');
3348 os << frontStrip(tmp_out, '@');
3352 } else if (font2.latex() == LyXFont::ON) {
3353 // "TeX"-Mode on == > SGML-Mode on.
3359 if (linuxDocConvertChar(c, sgml_string)
3360 && !style.free_spacing) {
3361 // in freespacing mode, spaces are
3362 // non-breaking characters
3367 << "</term><listitem><para>";
3377 // we have only to control for emphasis open here!
3379 os << "</emphasis>";
3382 font1 = font2 = getFont(bparams, -1);
3383 cell = table->CellHasContRow(current_cell_number);
3385 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3389 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3390 LyXParagraph::size_type const i,
3391 int & column, LyXFont const & font,
3392 LyXLayout const & style)
3394 if (column > tex_code_break_column
3396 && GetChar(i - 1) != ' '
3398 // In LaTeX mode, we don't want to
3399 // break lines since some commands
3401 && ! (font.latex() == LyXFont::ON)
3402 // same in FreeSpacing mode
3403 && !style.free_spacing
3404 // In typewriter mode, we want to avoid
3405 // ! . ? : at the end of a line
3406 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3407 && (GetChar(i-1) == '.'
3408 || GetChar(i-1) == '?'
3409 || GetChar(i-1) == ':'
3410 || GetChar(i-1) == '!'))) {
3411 if (tex_code_break_column == 0) {
3412 // in batchmode we need LaTeX to still
3413 // see it as a space not as an extra '\n'
3419 texrow.start(this, i + 1);
3421 } else if (font.latex() == LyXFont::OFF) {
3422 if (style.free_spacing) {
3431 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3432 BufferParams const & bparams,
3433 ostream & os, TexRow & texrow,
3436 LyXFont & running_font,
3439 LyXLayout const & style,
3440 LyXParagraph::size_type & i,
3442 LyXParagraph::value_type const c)
3444 // Two major modes: LaTeX or plain
3445 // Handle here those cases common to both modes
3446 // and then split to handle the two modes separately.
3448 case LyXParagraph::META_INSET: {
3449 Inset * inset = GetInset(i);
3452 int len = os.tellp();
3453 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3454 || inset->LyxCode() == Inset::MATH_CODE
3455 || inset->LyxCode() == Inset::URL_CODE)
3456 && running_font.isRightToLeft()) {
3461 int tmp = inset->Latex(buf, os, moving_arg,
3462 style.free_spacing);
3470 column += os.tellp() - len;
3479 case LyXParagraph::META_NEWLINE:
3481 column += running_font.latexWriteEndChanges(os,
3486 basefont = getFont(bparams, -1);
3487 running_font = basefont;
3490 case LyXParagraph::META_HFILL:
3496 // And now for the special cases within each mode
3497 // Are we in LaTeX mode?
3498 if (font.latex() == LyXFont::ON) {
3499 // at present we only have one option
3500 // but I'll leave it as a switch statement
3501 // so its simpler to extend. (ARRae)
3504 // make sure that we will not print
3505 // error generating chars to the tex
3506 // file. This test would not be needed
3507 // if it were done in the buffer
3515 // Plain mode (i.e. not LaTeX)
3518 os << "\\textbackslash{}";
3522 case '°': case '±': case '²': case '³':
3523 case '×': case '÷': case '¹': case 'ª':
3524 case 'º': case '¬': case 'µ':
3525 if (bparams.inputenc == "latin1" ||
3526 (bparams.inputenc == "auto" &&
3527 font.language()->encoding()->LatexName()
3529 os << "\\ensuremath{"
3538 case '|': case '<': case '>':
3539 // In T1 encoding, these characters exist
3540 if (lyxrc.fontenc == "T1") {
3542 //... but we should avoid ligatures
3543 if ((c == '>' || c == '<')
3545 && GetChar(i + 1) == c) {
3546 //os << "\\textcompwordmark{}";
3547 // Jean-Marc, have a look at
3548 // this. IÂ think this works
3556 // Typewriter font also has them
3557 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3561 // Otherwise, we use what LaTeX
3565 os << "\\textless{}";
3569 os << "\\textgreater{}";
3573 os << "\\textbar{}";
3579 case '-': // "--" in Typewriter mode -> "-{}-"
3581 && GetChar(i + 1) == '-'
3582 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3591 os << "\\char`\\\"{}";
3596 if (bparams.inputenc == "default") {
3605 case '%': case '#': case '{':
3612 os << "\\textasciitilde{}";
3617 os << "\\textasciicircum{}";
3621 case '*': case '[': case ']':
3622 // avoid being mistaken for optional arguments
3623 os << '{' << c << '}';
3628 // Blanks are printed before font switching.
3629 // Sure? I am not! (try nice-latex)
3630 // I am sure it's correct. LyX might be smarter
3631 // in the future, but for now, nothing wrong is
3636 /* idea for labels --- begin*/
3640 && font.family() != LyXFont::TYPEWRITER_FAMILY
3641 && GetChar(i + 1) == 'y'
3642 && GetChar(i + 2) == 'X') {
3650 && font.family() != LyXFont::TYPEWRITER_FAMILY
3651 && GetChar(i + 1) == 'e'
3652 && GetChar(i + 2) == 'X') {
3657 // Check for "LaTeX2e"
3660 && font.family() != LyXFont::TYPEWRITER_FAMILY
3661 && GetChar(i + 1) == 'a'
3662 && GetChar(i + 2) == 'T'
3663 && GetChar(i + 3) == 'e'
3664 && GetChar(i + 4) == 'X'
3665 && GetChar(i + 5) == '2'
3666 && GetChar(i + 6) == 'e') {
3671 // Check for "LaTeX"
3674 && font.family() != LyXFont::TYPEWRITER_FAMILY
3675 && GetChar(i + 1) == 'a'
3676 && GetChar(i + 2) == 'T'
3677 && GetChar(i + 3) == 'e'
3678 && GetChar(i + 4) == 'X') {
3682 /* idea for labels --- end*/
3683 } else if (c != '\0') {
3693 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3694 BufferParams const & bparams,
3695 ostream & os, TexRow & texrow,
3697 TexRow & foot_texrow,
3700 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3701 LyXParagraph * par = this;
3704 (par->depth == depth)
3706 && (par->footnoteflag == footnoteflag)
3711 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3713 if (textclasslist.Style(bparams.textclass,
3714 par->layout).isEnvironment()
3715 || par->pextra_type != PEXTRA_NONE) {
3716 par = par->TeXEnvironment(buf, bparams,
3721 par = par->TeXOnePar(buf, bparams,
3731 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3737 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3738 BufferParams const & bparams,
3739 ostream & os, TexRow & texrow,
3741 TexRow & foot_texrow,
3744 bool eindent_open = false;
3745 bool foot_this_level = false;
3746 // flags when footnotetext should be appended to file.
3747 static bool minipage_open = false;
3748 static int minipage_open_depth = 0;
3749 char par_sep = bparams.paragraph_separation;
3751 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3754 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3757 LyXLayout const & style =
3758 textclasslist.Style(bparams.textclass,
3761 if (pextra_type == PEXTRA_INDENT) {
3762 if (!pextra_width.empty()) {
3763 os << "\\begin{LyXParagraphIndent}{"
3764 << pextra_width << "}\n";
3766 //float ib = atof(pextra_widthp.c_str())/100;
3767 // string can't handle floats at present (971109)
3768 // so I'll do a conversion by hand knowing that
3769 // the limits are 0.0 to 1.0. ARRae.
3770 os << "\\begin{LyXParagraphIndent}{";
3771 switch (pextra_widthp.length()) {
3783 os << "\\columnwidth}\n";
3786 eindent_open = true;
3788 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3789 if (pextra_hfill && Previous() &&
3790 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3791 os << "\\hfill{}\n";
3794 if (par_sep == BufferParams::PARSEP_INDENT) {
3795 os << "{\\setlength\\parindent{0pt}\n";
3798 os << "\\begin{minipage}";
3799 switch(pextra_alignment) {
3800 case MINIPAGE_ALIGN_TOP:
3803 case MINIPAGE_ALIGN_MIDDLE:
3806 case MINIPAGE_ALIGN_BOTTOM:
3810 if (!pextra_width.empty()) {
3811 os << '{' << pextra_width << "}\n";
3813 //float ib = atof(par->pextra_width.c_str())/100;
3814 // string can't handle floats at present
3815 // so I'll do a conversion by hand knowing that
3816 // the limits are 0.0 to 1.0. ARRae.
3818 switch (pextra_widthp.length()) {
3830 os << "\\columnwidth}\n";
3833 if (par_sep == BufferParams::PARSEP_INDENT) {
3834 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3837 minipage_open = true;
3838 minipage_open_depth = depth;
3841 #ifdef WITH_WARNINGS
3842 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3843 //I disabled it because it breaks when lists span on several
3846 if (style.isEnvironment()){
3847 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3848 #ifdef FANCY_FOOTNOTE_CODE
3849 if (foot_count < 0) {
3850 // flag that footnote[mark][text] should be
3851 // used for any footnotes from now on
3853 foot_this_level = true;
3856 os << "\\begin{" << style.latexname() << "}{"
3857 << labelwidthstring << "}\n";
3858 } else if (style.labeltype == LABEL_BIBLIO) {
3860 os << "\\begin{" << style.latexname() << "}{"
3861 << bibitemWidest(current_view)
3863 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3864 #ifdef FANCY_FOOTNOTE_CODE
3865 if (foot_count < 0) {
3866 // flag that footnote[mark][text] should be
3867 // used for any footnotes from now on
3869 foot_this_level = true;
3872 os << "\\begin{" << style.latexname() << '}'
3873 << style.latexparam() << '\n';
3875 os << "\\begin{" << style.latexname() << '}'
3876 << style.latexparam() << '\n';
3879 LyXParagraph * par = this;
3881 par = par->TeXOnePar(buf, bparams,
3885 foot, foot_texrow, foot_count
3889 if (minipage_open && par && !style.isEnvironment() &&
3890 (par->pextra_type == PEXTRA_MINIPAGE) &&
3891 par->pextra_start_minipage) {
3892 os << "\\end{minipage}\n";
3894 if (par_sep == BufferParams::PARSEP_INDENT) {
3898 minipage_open = false;
3900 if (par && par->depth > depth) {
3901 if (textclasslist.Style(bparams.textclass,
3902 par->layout).isParagraph()
3905 // How to handle this? (Lgb)
3906 //&& !suffixIs(os, "\n\n")
3908 // There should be at least one '\n' already
3909 // but we need there to be two for Standard
3910 // paragraphs that are depth-increment'ed to be
3911 // output correctly. However, tables can
3912 // also be paragraphs so don't adjust them.
3915 // Will it ever harm to have one '\n' too
3916 // many? i.e. that we sometimes will have
3917 // three in a row. (Lgb)
3921 par = par->TeXDeeper(buf, bparams, os, texrow,
3922 foot, foot_texrow, foot_count);
3924 if (par && par->layout == layout && par->depth == depth &&
3925 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3926 if (par->pextra_hfill && par->Previous() &&
3927 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3928 os << "\\hfill{}\n";
3931 if (par_sep == BufferParams::PARSEP_INDENT) {
3932 os << "{\\setlength\\parindent{0pt}\n";
3935 os << "\\begin{minipage}";
3936 switch(par->pextra_alignment) {
3937 case MINIPAGE_ALIGN_TOP:
3940 case MINIPAGE_ALIGN_MIDDLE:
3943 case MINIPAGE_ALIGN_BOTTOM:
3947 if (!par->pextra_width.empty()) {
3948 os << '{' << par->pextra_width << "}\n";
3950 //float ib = atof(par->pextra_widthp.c_str())/100;
3951 // string can't handle floats at present
3952 // so I'll do a conversion by hand knowing that
3953 // the limits are 0.0 to 1.0. ARRae.
3955 switch (par->pextra_widthp.length()) {
3960 os << "0." << par->pextra_widthp;
3963 os << "0.0" << par->pextra_widthp;
3965 os << "\\columnwidth}\n";
3968 if (par_sep == BufferParams::PARSEP_INDENT) {
3969 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3972 minipage_open = true;
3973 minipage_open_depth = par->depth;
3976 && par->layout == layout
3977 && par->depth == depth
3978 && par->pextra_type == pextra_type
3980 && par->footnoteflag == footnoteflag
3984 if (style.isEnvironment()) {
3985 os << "\\end{" << style.latexname() << '}';
3986 // maybe this should go after the minipage closes?
3987 if (foot_this_level) {
3988 if (foot_count >= 1) {
3989 if (foot_count > 1) {
3990 os << "\\addtocounter{footnote}{-"
3995 texrow += foot_texrow;
3997 foot_texrow.reset();
4002 if (minipage_open && (minipage_open_depth == depth) &&
4003 (!par || par->pextra_start_minipage ||
4004 par->pextra_type != PEXTRA_MINIPAGE)) {
4005 os << "\\end{minipage}\n";
4007 if (par_sep == BufferParams::PARSEP_INDENT) {
4011 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
4012 os << "\\medskip\n\n";
4016 minipage_open = false;
4019 os << "\\end{LyXParagraphIndent}\n";
4022 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
4023 && par->pextra_hfill)) {
4027 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
4028 return par; // ale970302
4033 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
4034 BufferParams const & bparams,
4035 ostream & os, TexRow & texrow,
4036 ostream & foot, TexRow & foot_texrow,
4040 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
4041 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
4042 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4043 "No footnote!" << endl;
4045 LyXParagraph * par = this;
4046 LyXLayout const & style =
4047 textclasslist.Style(bparams.textclass,
4048 previous->GetLayout());
4050 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
4051 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4052 "Float other than footnote in command"
4053 " with moving argument is illegal" << endl;
4056 if (footnotekind != LyXParagraph::FOOTNOTE
4057 && footnotekind != LyXParagraph::MARGIN
4060 // How to solve this?
4061 //&& !suffixIs(file, '\n')
4063 // we need to ensure that real floats like tables and figures
4064 // have their \begin{} on a new line otherwise we can get
4065 // incorrect results when using the endfloat.sty package
4066 // especially if two floats follow one another. ARRae 981022
4067 // NOTE: if the file is length 0 it must have just been
4068 // written out so we assume it ended with a '\n'
4070 // As far as I can see there is never any harm in writing
4071 // a '\n' too much. Please tell me if I am wrong. (Lgb)
4076 bool moving_arg = false;
4077 bool need_closing = false;
4078 bool is_rtl = isRightToLeftPar(bparams);
4080 if (is_rtl != parent_is_rtl) {
4085 need_closing = true;
4088 //BufferParams * params = ¤t_view->buffer()->params;
4089 bool footer_in_body = true;
4090 switch (footnotekind) {
4091 case LyXParagraph::FOOTNOTE:
4092 if (style.intitle) {
4093 os << "\\thanks{\n";
4094 footer_in_body = false;
4097 if (foot_count == -1) {
4098 // we're at depth 0 so we can use:
4099 os << "\\footnote{%\n";
4100 footer_in_body = false;
4102 os << "\\footnotemark{}%\n";
4104 // we only need this when there are
4105 // multiple footnotes
4106 os << "\\stepcounter{footnote}";
4108 os << "\\footnotetext{%\n";
4109 foot_texrow.start(this, 0);
4110 foot_texrow.newline();
4115 case LyXParagraph::MARGIN:
4116 os << "\\marginpar{\n";
4118 case LyXParagraph::FIG:
4119 if (pextra_type == PEXTRA_FLOATFLT
4120 && (!pextra_width.empty()
4121 || !pextra_widthp.empty())) {
4122 if (!pextra_width.empty())
4123 os << "\\begin{floatingfigure}{"
4124 << pextra_width << "}\n";
4126 os << "\\begin{floatingfigure}{"
4127 << atoi(pextra_widthp.c_str())/100.0
4128 << "\\textwidth}\n";
4130 os << "\\begin{figure}";
4131 if (!bparams.float_placement.empty()) {
4132 os << '[' << bparams.float_placement << "]\n";
4138 case LyXParagraph::TAB:
4139 os << "\\begin{table}";
4140 if (!bparams.float_placement.empty()) {
4141 os << '[' << bparams.float_placement << "]\n";
4146 case LyXParagraph::WIDE_FIG:
4147 os << "\\begin{figure*}";
4148 if (!bparams.float_placement.empty()) {
4149 os << '[' << bparams.float_placement << "]\n";
4154 case LyXParagraph::WIDE_TAB:
4155 os << "\\begin{table*}";
4156 if (!bparams.float_placement.empty()) {
4157 os << '[' << bparams.float_placement << "]\n";
4162 case LyXParagraph::ALGORITHM:
4163 os << "\\begin{algorithm}\n";
4168 if (footnotekind != LyXParagraph::FOOTNOTE
4169 || !footer_in_body) {
4170 // Process text for all floats except footnotes in body
4172 LyXLayout const & style =
4174 .Style(bparams.textclass, par->layout);
4176 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4178 if (style.isEnvironment()
4179 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4180 // Allows the use of minipages within float
4181 // environments. Shouldn't be circular because
4182 // we don't support footnotes inside
4183 // floats (yet). ARRae
4184 par = par->TeXEnvironment(buf, bparams, os,
4189 par = par->TeXOnePar(buf, bparams,
4190 os, texrow, moving_arg,
4195 if (par && !par->IsDummy() && par->depth > depth) {
4196 par = par->TeXDeeper(buf, bparams, os, texrow,
4200 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4202 // process footnotes > depth 0 or in environments separately
4203 // NOTE: Currently don't support footnotes within footnotes
4204 // even though that is possible using the \footnotemark
4206 std::ostringstream dummy;
4210 TexRow dummy_texrow;
4211 int dummy_count = 0;
4213 LyXLayout const & style =
4215 .Style(bparams.textclass, par->layout);
4217 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4219 if (style.isEnvironment()
4220 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4221 // Allows the use of minipages within float
4222 // environments. Shouldn't be circular because
4223 // we don't support footnotes inside
4224 // floats (yet). ARRae
4225 par = par->TeXEnvironment(buf, bparams,
4227 dummy, dummy_texrow,
4230 par = par->TeXOnePar(buf, bparams,
4233 dummy, dummy_texrow,
4237 if (par && !par->IsDummy() && par->depth > depth) {
4238 par = par->TeXDeeper(buf, bparams,
4240 dummy, dummy_texrow,
4244 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4246 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4247 "Footnote in a Footnote -- not supported"
4250 #ifndef HAVE_OSTREAM
4251 delete [] dummy.str();
4255 switch (footnotekind) {
4256 case LyXParagraph::FOOTNOTE:
4257 if (footer_in_body) {
4258 // This helps tell which of the multiple
4259 // footnotetexts an error was in.
4261 foot_texrow.newline();
4266 case LyXParagraph::MARGIN:
4269 case LyXParagraph::FIG:
4270 if (pextra_type == PEXTRA_FLOATFLT
4271 && (!pextra_width.empty()
4272 || !pextra_widthp.empty()))
4273 os << "\\end{floatingfigure}";
4275 os << "\\end{figure}";
4277 case LyXParagraph::TAB:
4278 os << "\\end{table}";
4280 case LyXParagraph::WIDE_FIG:
4281 os << "\\end{figure*}";
4283 case LyXParagraph::WIDE_TAB:
4284 os << "\\end{table*}";
4286 case LyXParagraph::ALGORITHM:
4287 os << "\\end{algorithm}";
4294 if (footnotekind != LyXParagraph::FOOTNOTE
4295 && footnotekind != LyXParagraph::MARGIN) {
4296 // we need to ensure that real floats like tables and figures
4297 // have their \end{} on a line of their own otherwise we can
4298 // get incorrect results when using the endfloat.sty package.
4303 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4308 bool LyXParagraph::IsDummy() const
4310 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4311 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4315 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4316 int type, char const * width,
4317 char const * widthp)
4320 pextra_width = width;
4321 pextra_widthp = widthp;
4323 if (textclasslist.Style(bparams.textclass,
4324 layout).isEnvironment()) {
4329 while (par && (par->layout == layout)
4330 && (par->depth == depth)) {
4332 par = par->Previous();
4335 par = par->FirstPhysicalPar();
4337 while (par && par->depth > depth) {
4338 par = par->Previous();
4341 par = par->FirstPhysicalPar();
4346 while (par && (par->layout == layout)
4347 && (par->depth == depth)) {
4348 par->pextra_type = type;
4349 par->pextra_width = width;
4350 par->pextra_widthp = widthp;
4352 par = par->NextAfterFootnote();
4356 if (par && (par->depth > depth))
4357 par->SetPExtraType(bparams,
4358 type, width, widthp);
4360 while (par && ((par->depth > depth) || par->IsDummy()))
4361 par = par->NextAfterFootnote();
4363 while (par && ((par->depth > depth)))
4371 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4373 if (pextra_type == PEXTRA_NONE)
4376 pextra_type = PEXTRA_NONE;
4377 pextra_width.erase();
4378 pextra_widthp.erase();
4380 if (textclasslist.Style(bparams.textclass,
4381 layout).isEnvironment()) {
4386 while (par && (par->layout == layout)
4387 && (par->depth == depth)) {
4389 par = par->Previous();
4392 par = par->FirstPhysicalPar();
4394 while (par && par->depth > depth) {
4395 par = par->Previous();
4398 par = par->FirstPhysicalPar();
4403 while (par && (par->layout == layout)
4404 && (par->depth == depth)) {
4405 par->pextra_type = PEXTRA_NONE;
4406 par->pextra_width.erase();
4407 par->pextra_widthp.erase();
4409 par = par->NextAfterFootnote();
4413 if (par && (par->depth > depth))
4414 par->UnsetPExtraType(bparams);
4416 while (par && ((par->depth > depth) || par->IsDummy()))
4417 par = par->NextAfterFootnote();
4419 while (par && ((par->depth > depth)))
4427 bool LyXParagraph::IsHfill(size_type pos) const
4429 return IsHfillChar(GetChar(pos));
4433 bool LyXParagraph::IsInset(size_type pos) const
4435 return IsInsetChar(GetChar(pos));
4440 bool LyXParagraph::IsFloat(size_type pos) const
4442 return IsFloatChar(GetChar(pos));
4447 bool LyXParagraph::IsNewline(size_type pos) const
4449 return pos >= 0 && IsNewlineChar(GetChar(pos));
4453 bool LyXParagraph::IsSeparator(size_type pos) const
4455 return IsSeparatorChar(GetChar(pos));
4459 bool LyXParagraph::IsLineSeparator(size_type pos) const
4461 return IsLineSeparatorChar(GetChar(pos));
4465 bool LyXParagraph::IsKomma(size_type pos) const
4467 return IsKommaChar(GetChar(pos));
4471 /// Used by the spellchecker
4472 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4474 value_type c = GetChar(pos);
4475 if (IsLetterChar(c))
4477 // '\0' is not a letter, allthough every string contains "" (below)
4480 // We want to pass the ' and escape chars to ispell
4481 string extra = lyxrc.isp_esc_chars + '\'';
4485 return contains(extra, ch);
4489 bool LyXParagraph::IsWord(size_type pos ) const
4491 return IsWordChar(GetChar(pos)) ;
4496 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4500 return FirstPhysicalPar()->getParLanguage(bparams);
4507 return GetFirstFontSettings().language();
4510 for (size_type pos = 0; pos < size(); ++pos)
4512 return GetFontSettings(bparams, pos).language();
4513 return GetFirstFontSettings().language();
4517 return previous->getParLanguage(bparams);
4519 return bparams.language_info;
4523 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4525 return lyxrc.rtl_support && !table
4526 && getParLanguage(bparams)->RightToLeft();
4530 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4531 Language const * from, Language const * to)
4533 for(size_type i = 0; i < size(); ++i) {
4534 LyXFont font = GetFontSettings(bparams, i);
4535 if (font.language() == from) {
4536 font.setLanguage(to);
4543 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4545 Language const * doc_language =
4546 bparams.language_info;
4547 for(size_type i = 0; i < size(); ++i) {
4548 LyXFont font = GetFontSettings(bparams, i);
4549 if (font.language() != doc_language)
4556 // Convert the paragraph to a string.
4557 // Used for building the table of contents
4558 string LyXParagraph::String(Buffer const * buffer, bool label)
4560 BufferParams const & bparams = buffer->params;
4563 if (label && !IsDummy() && !labelstring.empty())
4565 if (label && !labelstring.empty())
4567 s += labelstring + ' ';
4568 string::size_type len = s.size();
4570 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4571 value_type c = GetChar(i);
4574 else if (c == META_INSET &&
4575 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4577 std::ostringstream ost;
4578 GetInset(i)->Ascii(buffer, ost);
4581 GetInset(i)->Ascii(buffer, ost);
4584 s += subst(ost.str(),'\n',' ');
4589 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4590 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4591 s += NextAfterFootnote()->String(buffer, false);
4595 if (isRightToLeftPar(bparams))
4596 reverse(s.begin() + len,s.end());
4604 string LyXParagraph::String(Buffer const * buffer,
4605 LyXParagraph::size_type beg,
4606 LyXParagraph::size_type end)
4613 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4615 if (cell >= table->NumberOfCellsInRow(actcell))
4624 if (beg == 0 && !IsDummy() && !labelstring.empty())
4626 if (beg == 0 && !labelstring.empty())
4628 s += labelstring + ' ';
4630 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4631 value_type c = GetChar(i);
4634 else if (c == META_INSET) {
4636 std::ostringstream ost;
4637 GetInset(i)->Ascii(buffer, ost);
4640 GetInset(i)->Ascii(buffer, ost);
4644 } else if (table && IsNewlineChar(c)) {
4645 if (cell >= table->NumberOfCellsInRow(actcell)) {
4660 void LyXParagraph::SetInsetOwner(Inset *i)
4663 for (InsetList::const_iterator cit = insetlist.begin();
4664 cit != insetlist.end(); ++cit) {
4666 (*cit).inset->setOwner(i);
4671 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4674 for (InsetList::const_iterator cit = insetlist.begin();
4675 cit != insetlist.end(); ++cit) {
4677 if ((*cit).inset->IsTextInset()) {
4678 static_cast<UpdatableInset *>
4679 ((*cit).inset)->deleteLyXText(bv);
4686 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4689 for (InsetList::const_iterator cit = insetlist.begin();
4690 cit != insetlist.end(); ++cit) {
4692 if ((*cit).inset->IsTextInset()) {
4693 static_cast<UpdatableInset *>
4694 ((*cit).inset)->resizeLyXText(bv);