1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 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 "support/filetools.h"
33 #include "lyx_gui_misc.h"
37 extern void addNewlineAndDepth(string & file, int const depth); // Jug 990923
38 int tex_code_break_column = 72; // needs non-zero initialization. set later.
39 // this is a bad idea, but how can LyXParagraph find its buffer to get
40 // parameters? (JMarc)
41 extern BufferView * current_view;
46 extern string bibitemWidthest();
48 // this is a minibuffer
49 static char minibuffer_char;
50 static LyXFont minibuffer_font;
51 static Inset * minibuffer_inset;
54 // Initialization of the counter for the paragraph id's,
55 // declared in lyxparagraph.h
56 unsigned int LyXParagraph::paragraph_id = 0;
59 LyXParagraph::LyXParagraph()
61 text.reserve(500); // is this number too big?
63 for (int i = 0; i < 10; ++i) setCounter(i , 0);
69 #ifndef NEW_FONTTABLE // OK
72 #ifndef NEW_INSETTABLE
75 footnoteflag = LyXParagraph::NO_FOOTNOTE;
77 align = LYX_ALIGN_BLOCK;
79 /* table stuff -- begin*/
81 /* table stuff -- end*/
83 bibkey = 0; // ale970302
88 // This konstruktor inserts the new paragraph in a list.
89 LyXParagraph::LyXParagraph(LyXParagraph * par)
92 par->text.resize(par->text.size());
94 for (int i = 0; i < 10; ++i) setCounter(i, 0);
98 // double linked list begin
101 next->previous = this;
103 previous->next = this;
105 #ifndef NEW_FONTTABLE // OK
108 #ifndef NEW_INSETTABLE
111 footnoteflag = LyXParagraph::NO_FOOTNOTE;
112 footnotekind = LyXParagraph::FOOTNOTE;
114 /* table stuff -- begin*/
116 /* table stuff -- end*/
117 id_ = paragraph_id++;
119 bibkey = 0; // ale970302
125 void LyXParagraph::writeFile(ostream & os, BufferParams & params,
126 char footflag, char dth)
128 LyXFont font1, font2;
134 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
136 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
138 // The beginning or the end of a footnote environment?
139 if (footflag != footnoteflag) {
140 footflag = footnoteflag;
142 os << "\n\\begin_float "
143 << string_footnotekinds[footnotekind]
147 os << "\n\\end_float ";
151 // The beginning or end of a deeper (i.e. nested) area?
154 while (depth > dth) {
155 os << "\n\\begin_deeper ";
160 while (depth < dth) {
161 os << "\n\\end_deeper ";
167 // First write the layout
169 << textclasslist.NameOfLayout(params.textclass, layout)
172 // Maybe some vertical spaces.
173 if (added_space_top.kind() != VSpace::NONE)
174 os << "\\added_space_top "
175 << added_space_top.asLyXCommand() << " ";
176 if (added_space_bottom.kind() != VSpace::NONE)
177 os << "\\added_space_bottom "
178 << added_space_bottom.asLyXCommand() << " ";
180 // The labelwidth string used in lists.
181 if (!labelwidthstring.empty())
182 os << "\\labelwidthstring "
183 << labelwidthstring << '\n';
185 // Lines above or below?
189 os << "\\line_bottom ";
191 // Pagebreaks above or below?
193 os << "\\pagebreak_top ";
194 if (pagebreak_bottom)
195 os << "\\pagebreak_bottom ";
197 // Start of appendix?
198 if (start_of_appendix)
199 os << "\\start_of_appendix ";
206 if (align != LYX_ALIGN_LAYOUT) {
208 case LYX_ALIGN_LEFT: h = 1; break;
209 case LYX_ALIGN_RIGHT: h = 2; break;
210 case LYX_ALIGN_CENTER: h = 3; break;
211 default: h = 0; break;
213 os << "\\align " << string_align[h] << " ";
215 if (pextra_type != PEXTRA_NONE) {
216 os << "\\pextra_type " << pextra_type;
217 if (pextra_type == PEXTRA_MINIPAGE) {
218 os << " \\pextra_alignment "
221 os << " \\pextra_hfill "
223 if (pextra_start_minipage)
224 os << " \\pextra_start_minipage "
225 << pextra_start_minipage;
227 if (!pextra_width.empty()) {
228 os << " \\pextra_width "
229 << VSpace(pextra_width).asLyXCommand();
230 } else if (!pextra_widthp.empty()) {
231 os << " \\pextra_widthp "
238 // Dummy layout. This means that a footnote ended.
239 os << "\n\\end_float ";
240 footflag = LyXParagraph::NO_FOOTNOTE;
243 // It might be a table.
245 os << "\\LyXTable\n";
253 font1 = LyXFont(LyXFont::ALL_INHERIT);
256 for (size_type i = 0; i < size(); i++) {
262 // Write font changes
263 font2 = GetFontSettings(i);
264 if (font2 != font1) {
265 font2.lyxWriteChanges(font1, os);
275 if (inset->DirectWrite()) {
276 // international char, let it write
277 // code directly so it's shorter in
281 os << "\n\\begin_inset ";
283 os << "\n\\end_inset \n\n";
288 os << "\n\\newline \n";
292 os << "\n\\hfill \n";
295 case META_PROTECTED_SEPARATOR:
296 os << "\n\\protected_separator \n";
300 os << "\n\\backslash \n";
304 if (i + 1 < size() && GetChar(i + 1) == ' ') {
311 if ((column > 70 && c == ' ')
316 // this check is to amend a bug. LyX sometimes
317 // inserts '\0' this could cause problems.
321 lyxerr << "ERROR (LyXParagraph::writeFile):"
322 " NULL char in structure." << endl;
328 // now write the next paragraph
330 next->writeFile(os, params, footflag, dth);
334 void LyXParagraph::validate(LaTeXFeatures & features)
336 // this will be useful later
337 LyXLayout const & layout =
338 textclasslist.Style(current_view->buffer()->params.textclass,
342 if (line_top || line_bottom)
343 features.lyxline = true;
346 features.layout[GetLayout()] = true;
349 #ifdef NEW_FONTTABLE // OK, but does not affect structure anyway
350 for (FontList::const_iterator cit = fontlist.begin();
351 cit != fontlist.end(); ++cit) {
352 if ((*cit).font.noun() == LyXFont::ON) {
353 lyxerr[Debug::LATEX] << "font.noun: "
354 << (*cit).font.noun()
356 features.noun = true;
357 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
358 << (*cit).font.stateText()
361 switch ((*cit).font.color()) {
363 case LyXFont::INHERIT_COLOR:
364 case LyXFont::IGNORE_COLOR:
367 features.color = true;
368 lyxerr[Debug::LATEX] << "Color enabled. Font: "
369 << (*cit).font.stateText()
374 FontTable * tmpfonttable = fonttable;
375 while (tmpfonttable) {
376 if (tmpfonttable->font.noun() == LyXFont::ON) {
377 lyxerr[Debug::LATEX] << "font.noun: "
378 << tmpfonttable->font.noun()
380 features.noun = true;
381 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
382 << tmpfonttable->font.stateText()
385 switch (tmpfonttable->font.color()) {
387 case LyXFont::INHERIT_COLOR:
388 case LyXFont::IGNORE_COLOR:
391 features.color = true;
392 lyxerr[Debug::LATEX] << "Color enabled. Font: "
393 << tmpfonttable->font.stateText()
396 tmpfonttable = tmpfonttable->next;
400 #ifdef NEW_INSETTABLE
401 for (InsetList::const_iterator cit = insetlist.begin();
402 cit != insetlist.end(); ++cit) {
404 (*cit).inset->Validate(features);
407 InsetTable * tmpinsettable = insettable;
408 while (tmpinsettable) {
409 if (tmpinsettable->inset) {
410 tmpinsettable->inset->Validate(features);
412 tmpinsettable = tmpinsettable->next;
416 if (table && table->IsLongTable())
417 features.longtable = true;
418 if (pextra_type == PEXTRA_INDENT)
419 features.LyXParagraphIndent = true;
420 if (pextra_type == PEXTRA_FLOATFLT)
421 features.floatflt = true;
422 if (layout.needprotect
423 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
424 features.NeedLyXFootnoteCode = true;
425 if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
426 (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
427 features.NeedLyXMinipageIndent = true;
428 if (table && table->NeedRotating())
429 features.rotating = true;
430 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
431 features.algorithm = true;
435 // First few functions needed for cut and paste and paragraph breaking.
436 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
438 minibuffer_char = GetChar(pos);
439 minibuffer_font = GetFontSettings(pos);
440 minibuffer_inset = 0;
441 if (minibuffer_char == LyXParagraph::META_INSET) {
443 minibuffer_inset = GetInset(pos)->Clone();
445 minibuffer_inset = 0;
446 minibuffer_char = ' ';
447 // This reflects what GetInset() does (ARRae)
453 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
455 minibuffer_char = GetChar(pos);
456 minibuffer_font = GetFontSettings(pos);
457 minibuffer_inset = 0;
458 if (minibuffer_char == LyXParagraph::META_INSET) {
460 minibuffer_inset = GetInset(pos);
461 // This is a little hack since I want exactly
462 // the inset, not just a clone. Otherwise
463 // the inset would be deleted when calling Erase(pos)
465 #ifdef NEW_INSETTABLE
466 for (InsetList::iterator it = insetlist.begin();
467 it != insetlist.end(); ++it) {
468 if ((*it).pos == pos) {
475 InsetTable * tmpi = insettable;
476 while (tmpi && tmpi->pos != pos) {
479 if (tmpi) { // This should always be true.
484 minibuffer_inset = 0;
485 minibuffer_char = ' ';
486 // This reflects what GetInset() does (ARRae)
491 // Erase(pos); now the caller is responsible for that.
495 void LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
497 InsertChar(pos, minibuffer_char);
498 SetFont(pos, minibuffer_font);
499 if (minibuffer_char == LyXParagraph::META_INSET)
500 InsertInset(pos, minibuffer_inset);
507 void LyXParagraph::Clear()
512 pagebreak_top = false;
513 pagebreak_bottom = false;
515 added_space_top = VSpace(VSpace::NONE);
516 added_space_bottom = VSpace(VSpace::NONE);
518 align = LYX_ALIGN_LAYOUT;
522 pextra_type = PEXTRA_NONE;
523 pextra_width.clear();
524 pextra_widthp.clear();
525 pextra_alignment = MINIPAGE_ALIGN_TOP;
526 pextra_hfill = false;
527 pextra_start_minipage = false;
530 labelwidthstring.clear();
534 start_of_appendix = false;
538 // the destructor removes the new paragraph from the list
539 LyXParagraph::~LyXParagraph()
542 previous->next = next;
544 next->previous = previous;
546 #ifdef NEW_INSETTABLE
547 for (InsetList::iterator it = insetlist.begin();
548 it != insetlist.end(); ++it) {
552 InsetTable * tmpinset;
554 tmpinset = insettable;
555 insettable = insettable->next;
557 delete tmpinset->inset;
559 if (insettable && insettable->next == insettable) {
560 // somehow this recursion appears occasionally
561 // but I can't find where. This bandaid
562 // helps but isn't the best fix. (ARRae)
563 if (insettable->inset) {
564 delete insettable->inset;
571 #ifndef NEW_FONTTABLE // OK
575 fonttable = fonttable->next;
580 /* table stuff -- begin*/
583 /* table stuff -- end*/
591 void LyXParagraph::Erase(LyXParagraph::size_type pos)
593 // > because last is the next unused position, and you can
594 // use it if you want
596 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
597 NextAfterFootnote()->Erase(pos - text.size() - 1);
599 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
600 "position does not exist." << endl;
603 if (pos < size()) { // last is free for insertation, but should be empty
604 // if it is an inset, delete the inset entry
605 if (text[pos] == LyXParagraph::META_INSET) {
607 #ifdef NEW_INSETTABLE
608 for (InsetList::iterator it = insetlist.begin();
609 it != insetlist.end(); ++it) {
610 if ((*it).pos == pos) {
617 InsetTable *tmpi = insettable;
618 InsetTable *tmpi2 = tmpi;
619 while (tmpi && tmpi->pos != pos) {
623 if (tmpi) { // this should always be true
624 if (tmpi->inset) // delete the inset if it exists
626 if (tmpi == insettable)
627 insettable = tmpi->next;
629 tmpi2->next = tmpi->next;
634 text.erase(text.begin() + pos);
635 // Erase entries in the tables.
636 #ifdef NEW_FONTTABLE // Seems OK
637 for (FontList::iterator it = fontlist.begin();
638 it != fontlist.end(); ++it) {
639 if (pos >= (*it).pos && pos <= (*it).pos_end) {
640 if ((*it).pos == (*it).pos_end) {
641 // If it is a multi-character font
642 // entry, we just make it smaller
643 // (see update below), otherwise we
650 // Update all other entries.
651 for (FontList::iterator it = fontlist.begin();
652 it != fontlist.end(); ++it) {
655 if ((*it).pos_end >= pos)
660 FontTable * tmp = fonttable;
661 FontTable * prev = 0;
662 while (tmp && !found) {
663 if (pos >= tmp->pos && pos <= tmp->pos_end)
671 if (found && tmp->pos == tmp->pos_end) {
672 // if it is a multi-character font entry, we just make
673 // it smaller (see update below), otherwise we should
676 prev->next = tmp->next;
678 fonttable = tmp->next;
683 // Update all other entries.
689 if (tmp->pos_end >= pos)
694 // Update the inset table.
695 #ifdef NEW_INSETTABLE
696 for (InsetList::iterator it = insetlist.begin();
697 it != insetlist.end(); ++it) {
702 InsetTable * tmpi = insettable;
710 lyxerr << "ERROR (LyXParagraph::Erase): "
711 "can't erase non-existant char." << endl;
716 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
718 // > because last is the next unused position, and you can
719 // use it if you want
722 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
723 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
726 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
727 "position does not exist." << endl;
730 text.insert(text.begin() + pos, c);
731 // Update the font table.
732 #ifdef NEW_FONTTABLE // Seems OK
733 for (FontList::iterator it = fontlist.begin();
734 it != fontlist.end(); ++it) {
735 if ((*it).pos >= pos)
737 if ((*it).pos_end >= pos)
741 FontTable * tmp = fonttable;
745 if (tmp->pos_end >= pos)
751 // Update the inset table.
752 #ifdef NEW_INSETTABLE
753 for (InsetList::iterator it = insetlist.begin();
754 it != insetlist.end(); ++it) {
755 if ((*it).pos >= pos)
759 InsetTable * tmpi = insettable;
761 if (tmpi->pos >= pos)
769 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
772 // > because last is the next unused position, and you can
773 // use it if you want
776 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
778 ->InsertInset(pos - text.size() - 1, inset);
780 lyxerr << "ERROR (LyXParagraph::InsertInset): "
781 "position does not exist: " << pos << endl;
784 if (text[pos] != LyXParagraph::META_INSET) {
785 lyxerr << "ERROR (LyXParagraph::InsertInset): "
786 "there is no LyXParagraph::META_INSET" << endl;
791 // Add a new entry in the inset table.
792 #ifdef NEW_INSETTABLE
794 InsetList::iterator it =
795 insetlist.insert(insetlist.begin(), tmpi);
799 InsetTable * tmpi = new InsetTable;
802 tmpi->next = insettable;
809 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
813 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
814 return NextAfterFootnote()
815 ->GetInset(pos - text.size() - 1);
817 lyxerr << "ERROR (LyXParagraph::GetInset): "
818 "position does not exist: "
824 #ifdef NEW_INSETTABLE
825 for (InsetList::iterator it = insetlist.begin();
826 it != insetlist.end(); ++it) {
827 if ((*it).pos == pos) {
831 lyxerr << "ERROR (LyXParagraph::GetInset): "
832 "Inset does not exist: " << pos << endl;
833 text[pos] = ' '; // WHY!!! does this set the pos to ' '????
834 // Did this commenting out introduce a bug? So far I have not
835 // see any, please enlighten me. (Lgb)
836 // My guess is that since the inset does not exist, we might
837 // as well replace it with a space to prevent craches. (Asger)
840 InsetTable * tmpi = insettable;
842 while (tmpi && tmpi->pos != pos)
848 lyxerr << "ERROR (LyXParagraph::GetInset): "
849 "Inset does not exist: " << pos << endl;
850 text[pos] = ' '; /// WHY!!! does this set the pos to ' '????
851 // Did this commenting out introduce a bug? So far I have not
852 // seen any, please enlighten me. (Lgb)
853 // My guess is that since the inset does not exist, we might
854 // as well replace it with a space to prevent crashes. (Asger)
861 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
865 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
866 return NextAfterFootnote()
867 ->GetInset(pos - text.size() - 1);
869 lyxerr << "ERROR (LyXParagraph::GetInset): "
870 "position does not exist: "
876 #ifdef NEW_INSETTABLE
877 for (InsetList::const_iterator cit = insetlist.begin();
878 cit != insetlist.end(); ++cit) {
879 if ((*cit).pos == pos) {
883 lyxerr << "ERROR (LyXParagraph::GetInset): "
884 "Inset does not exist: " << pos << endl;
885 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
886 // Did this commenting out introduce a bug? So far I have not
887 // see any, please enlighten me. (Lgb)
888 // My guess is that since the inset does not exist, we might
889 // as well replace it with a space to prevent craches. (Asger)
892 InsetTable * tmpi = insettable;
894 while (tmpi && tmpi->pos != pos)
900 lyxerr << "ERROR (LyXParagraph::GetInset): "
901 "Inset does not exist: " << pos << endl;
902 // in the const version we need to comment it out anyway...
903 //text[pos] = ' '; /// WHY!!! does this set the pos to ' '????
904 // Did this commenting out introduce a bug? So far I have not
905 // seen any, please enlighten me. (Lgb)
906 // My guess is that since the inset does not exist, we might
907 // as well replace it with a space to prevent crashes. (Asger)
914 // Gets uninstantiated font setting at position.
915 // Optimized after profiling. (Asger)
916 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
919 #ifdef NEW_FONTTABLE // Seems OK
920 for (FontList::const_iterator cit = fontlist.begin();
921 cit != fontlist.end(); ++cit) {
922 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
926 FontTable * tmp = fonttable;
928 if (pos >= tmp->pos && pos <= tmp->pos_end)
934 // > because last is the next unused position, and you can
935 // use it if you want
936 else if (pos > size()) {
938 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
939 return NextAfterFootnote()
940 ->GetFontSettings(pos - text.size() - 1);
942 // Why is it an error to ask for the font of a
943 // position that does not exist? Would it be
944 // enough for this to be enabled on debug?
945 // We want strict error checking, but it's ok to only
946 // have it when debugging. (Asger)
947 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
948 "position does not exist. "
949 << pos << " (" << static_cast<int>(pos)
953 return GetFontSettings(pos - 1);
955 return LyXFont(LyXFont::ALL_INHERIT);
959 // Gets the fully instantiated font at a given position in a paragraph
960 // This is basically the same function as LyXText::GetFont() in text2.C.
961 // The difference is that this one is used for generating the LaTeX file,
962 // and thus cosmetic "improvements" are disallowed: This has to deliver
963 // the true picture of the buffer. (Asger)
964 // If position is -1, we get the layout font of the paragraph.
965 // If position is -2, we get the font of the manual label of the paragraph.
966 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
969 LyXLayout const & layout =
970 textclasslist.Style(current_view->buffer()->params.textclass,
972 LyXParagraph::size_type main_body = 0;
973 if (layout.labeltype == LABEL_MANUAL)
974 main_body = BeginningOfMainBody();
979 layoutfont = layout.labelfont;
981 layoutfont = layout.font;
982 tmpfont = GetFontSettings(pos);
983 tmpfont.realize(layoutfont);
985 // process layoutfont for pos == -1 and labelfont for pos < -1
987 tmpfont = layout.font;
989 tmpfont = layout.labelfont;
992 // check for environment font information
993 char par_depth = GetDepth();
994 LyXParagraph const * par = this;
995 while (par && par_depth && !tmpfont.resolved()) {
996 par = par->DepthHook(par_depth - 1);
998 tmpfont.realize(textclasslist.
999 Style(current_view->buffer()->params.textclass,
1000 par->GetLayout()).font);
1001 par_depth = par->GetDepth();
1005 tmpfont.realize(textclasslist
1006 .TextClass(current_view->buffer()->params.textclass)
1012 /// Returns the height of the highest font in range
1014 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
1015 LyXParagraph::size_type endpos) const
1017 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
1018 #ifdef NEW_FONTTABLE // Seems OK
1019 for (FontList::const_iterator cit = fontlist.begin();
1020 cit != fontlist.end(); ++cit) {
1021 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
1022 LyXFont::FONT_SIZE size = (*cit).font.size();
1023 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
1028 FontTable * tmp = fonttable;
1030 if (startpos <= tmp->pos_end && endpos >= tmp->pos) {
1031 LyXFont::FONT_SIZE size = tmp->font.size();
1032 if (size > maxsize && size<= LyXFont::SIZE_HUGER)
1042 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
1049 // > because last is the next unused position, and you can
1050 // use it if you want
1051 else if (pos > size()) {
1052 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1053 return NextAfterFootnote()
1054 ->GetChar(pos - text.size() - 1);
1056 lyxerr << "ERROR (LyXParagraph::GetChar): "
1057 "position does not exist."
1058 << pos << " (" << static_cast<int>(pos)
1064 // We should have a footnote environment.
1065 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1066 // Notice that LyX does request the
1067 // last char from time to time. (Asger)
1068 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1069 // "expected footnote." << endl;
1072 switch (next->footnotekind) {
1073 case LyXParagraph::FOOTNOTE:
1074 return LyXParagraph::META_FOOTNOTE;
1075 case LyXParagraph::MARGIN:
1076 return LyXParagraph::META_MARGIN;
1077 case LyXParagraph::FIG:
1078 case LyXParagraph::WIDE_FIG:
1079 return LyXParagraph::META_FIG;
1080 case LyXParagraph::TAB:
1081 case LyXParagraph::WIDE_TAB:
1082 return LyXParagraph::META_TAB;
1083 case LyXParagraph::ALGORITHM:
1084 return LyXParagraph::META_ALGORITHM;
1086 return '\0'; // to shut up gcc
1091 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
1098 // > because last is the next unused position, and you can
1099 // use it if you want
1100 else if (pos > size()) {
1101 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1102 return NextAfterFootnote()
1103 ->GetChar(pos - text.size() - 1);
1105 lyxerr << "ERROR (LyXParagraph::GetChar const): "
1106 "position does not exist."
1107 << pos << " (" << static_cast<int>(pos)
1113 // We should have a footnote environment.
1114 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1115 // Notice that LyX does request the
1116 // last char from time to time. (Asger)
1117 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1118 // "expected footnote." << endl;
1121 switch (next->footnotekind) {
1122 case LyXParagraph::FOOTNOTE:
1123 return LyXParagraph::META_FOOTNOTE;
1124 case LyXParagraph::MARGIN:
1125 return LyXParagraph::META_MARGIN;
1126 case LyXParagraph::FIG:
1127 case LyXParagraph::WIDE_FIG:
1128 return LyXParagraph::META_FIG;
1129 case LyXParagraph::TAB:
1130 case LyXParagraph::WIDE_TAB:
1131 return LyXParagraph::META_TAB;
1132 case LyXParagraph::ALGORITHM:
1133 return LyXParagraph::META_ALGORITHM;
1135 return '\0'; // to shut up gcc
1140 // return an string of the current word, and the end of the word in lastpos.
1141 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1145 // the current word is defined as starting at the first character
1146 // from the immediate left of lastpospos which meets the definition
1147 // of IsLetter(), continuing to the last character to the right
1148 // of this meeting IsLetter.
1154 // move back until we have a letter
1156 //there's no real reason to have firstpos & lastpos as
1157 //separate variables as this is written, but maybe someon
1158 // will want to return firstpos in the future.
1160 //since someone might have typed a punctuation first
1161 int firstpos = lastpos;
1163 while ((firstpos >= 0) && !IsLetter(firstpos))
1166 // now find the beginning by looking for a nonletter
1168 while ((firstpos>= 0) && IsLetter(firstpos))
1171 // the above is now pointing to the preceeding non-letter
1175 // so copy characters into theword until we get a nonletter
1176 // note that this can easily exceed lastpos, wich means
1177 // that if used in the middle of a word, the whole word
1180 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1187 LyXParagraph::size_type LyXParagraph::Last() const
1189 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1190 return text.size() + NextAfterFootnote()->Last() + 1;
1191 // the 1 is the symbol
1198 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1200 // > because last is the next unused position, and you can
1201 // use it if you want
1204 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1205 return NextAfterFootnote()
1206 ->ParFromPos(pos - text.size() - 1);
1208 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1209 "position does not exist." << endl;
1216 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1218 // > because last is the next unused position, and you can
1219 // use it if you want
1222 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1223 return NextAfterFootnote()
1224 ->PositionInParFromPos(pos - text.size() - 1);
1227 "ERROR (LyXParagraph::PositionInParFromPos): "
1228 "position does not exist." << endl;
1236 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1237 LyXFont const & font)
1239 // > because last is the next unused position, and you can
1240 // use it if you want
1243 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1244 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1247 lyxerr << "ERROR (LyXParagraph::SetFont): "
1248 "position does not exist." << endl;
1252 LyXFont patternfont(LyXFont::ALL_INHERIT);
1254 // First, reduce font against layout/label font
1255 // Update: The SetCharFont() routine in text2.C already
1256 // reduces font, so we don't need to do that here. (Asger)
1257 // No need to simplify this because it will disappear
1258 // in a new kernel. (Asger)
1259 // Next search font table
1260 #ifdef NEW_FONTTABLE
1261 FontList::iterator tmp = fontlist.begin();
1262 for (; tmp != fontlist.end(); ++tmp) {
1263 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1267 if (tmp == fontlist.end()) { // !found
1268 // if we did not find a font entry, but if the font at hand
1269 // is the same as default, we just forget it
1270 if (font == patternfont) return;
1272 // ok, we did not find a font entry. But maybe there is exactly
1273 // the needed font ientry one position left
1274 FontList::iterator tmp2 = fontlist.begin();
1275 for (; tmp2 != fontlist.end(); ++tmp2) {
1276 if (pos - 1 >= (*tmp2).pos
1277 && pos - 1 <= (*tmp2).pos_end)
1280 if (tmp2 != fontlist.end()) {
1281 // ok there is one, maybe it is exactly
1283 if ((*tmp2).font == font) {
1284 // put the position under the font
1289 // Add a new entry in the
1290 // fontlist for the position
1294 ft.font = font; // or patternfont
1295 // It seems that using font instead of patternfont here
1296 // fixes all the problems. This also surfaces a "bug" in
1298 fontlist.insert(fontlist.begin(), ft);
1299 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1301 // more than one character
1302 if (pos == (*tmp).pos) {
1303 // maybe we should enlarge the left fonttable
1304 FontList::iterator tmp2 = fontlist.begin();
1305 for (; tmp2 != fontlist.end(); ++tmp2) {
1306 if (pos - 1 >= (*tmp2).pos
1307 && pos - 1 <= (*tmp2).pos_end)
1310 // Is there is one, and is it exactly
1312 if (tmp2 != fontlist.end() &&
1313 (*tmp2).font == font) {
1314 // Put the position under the font
1320 // Add a new entry in the
1321 // fontlist for the position
1324 ft.pos_end = (*tmp).pos_end;
1325 ft.font = (*tmp).font;
1326 (*tmp).pos_end = pos;
1328 fontlist.insert(fontlist.begin(), ft);
1329 } else if (pos == (*tmp).pos_end) {
1330 // Add a new entry in the
1331 // fontlist for the position
1333 ft.pos = (*tmp).pos;
1334 ft.pos_end = (*tmp).pos_end - 1;
1335 ft.font = (*tmp).font;
1336 (*tmp).pos = (*tmp).pos_end;
1338 fontlist.insert(fontlist.begin(), ft);
1340 // Add a new entry in the
1341 // fontlist for the position
1343 ft.pos = (*tmp).pos;
1344 ft.pos_end = pos - 1;
1345 ft.font = (*tmp).font;
1349 ft2.pos_end = (*tmp).pos_end;
1350 ft2.font = (*tmp).font;
1353 (*tmp).pos_end = pos;
1356 fontlist.insert(fontlist.begin(), ft);
1357 fontlist.insert(fontlist.begin(), ft2);
1367 FontTable * tmp = fonttable;
1368 while (tmp && !found) {
1369 if (pos >= tmp->pos && pos <= tmp->pos_end)
1376 // if we did not find a font entry, but if the font at hand
1377 // is the same as default, we just forget it
1378 if (font == patternfont)
1381 // ok, we did not find a font entry. But maybe there is exactly
1382 // the needed font entry one position left
1385 while (tmp2 && !found) {
1386 if (pos - 1 >= tmp2->pos && pos - 1 <= tmp2->pos_end)
1392 // ok there is one. maybe it is exactly
1394 if (tmp2->font == font) {
1395 // put the position under the font
1400 // Add a new entry in the
1401 // fonttable for the position
1402 tmp = new FontTable;
1405 tmp->font = patternfont; // It seems that is actually totally
1406 // wrong to use patternfont here, the correct should be font
1407 // lockily at the end of this function we have
1408 // tmp->font = font, so this one setting it to patternfont
1410 tmp->next = fonttable;
1413 // we found a font entry. maybe we have
1414 // to split it and create a new one
1416 if (tmp->pos != tmp->pos_end) { // more than one character
1417 if (pos == tmp->pos) {
1418 // maybe we could enlarge the left fonttable
1421 while (tmp2 && !found) {
1422 if (pos - 1 >= tmp2->pos && pos - 1 <= tmp2->pos_end)
1428 // Is there is one, and is it exactly
1430 if (found && tmp2->font == font) {
1431 // Put the position under the font
1437 // Add a new entry in the
1438 // fonttable for the position
1439 tmp2 = new FontTable;
1440 tmp2->pos = pos + 1;
1441 tmp2->pos_end = tmp->pos_end;
1442 tmp2->font = tmp->font;
1444 tmp2->next = fonttable;
1447 else if (pos == tmp->pos_end) {
1448 // Add a new entry in the
1449 // fonttable for the position
1450 tmp2 = new FontTable;
1451 tmp2->pos = tmp->pos;
1452 tmp2->pos_end = tmp->pos_end - 1;
1453 tmp2->font = tmp->font;
1454 tmp->pos = tmp->pos_end;
1455 tmp2->next = fonttable;
1459 // Add a new entry in the
1460 // fonttable for the position
1461 tmp2 = new FontTable;
1462 tmp2->pos = tmp->pos;
1463 tmp2->pos_end = pos - 1;
1464 tmp2->font = tmp->font;
1465 tmp2->next = fonttable;
1468 tmp2 = new FontTable;
1469 tmp2->pos = pos + 1;
1470 tmp2->pos_end = tmp->pos_end;
1471 tmp2->font = tmp->font;
1472 tmp2->next = fonttable;
1485 // This function is able to hide closed footnotes.
1486 LyXParagraph * LyXParagraph::Next()
1488 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1489 LyXParagraph * tmp = next;
1491 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1493 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1494 return tmp->Next(); /* there can be more than one
1495 footnote in a logical
1498 return next; // This should never happen!
1504 LyXParagraph * LyXParagraph::NextAfterFootnote()
1506 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1507 LyXParagraph * tmp = next;
1508 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1510 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1511 return tmp; /* there can be more than one footnote
1512 in a logical paragraph */
1514 return next; // This should never happen!
1520 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1522 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1523 LyXParagraph * tmp = next;
1524 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1526 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1527 return tmp; /* there can be more than one footnote
1528 in a logical paragraph */
1530 return next; // This should never happen!
1536 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1539 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1541 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1542 tmp = tmp->previous;
1543 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1544 return tmp; /* there can be more than one footnote
1545 in a logical paragraph */
1547 return previous; // This should never happen!
1553 LyXParagraph * LyXParagraph::LastPhysicalPar()
1555 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1558 LyXParagraph * tmp = this;
1560 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1561 tmp = tmp->NextAfterFootnote();
1568 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1572 LyXParagraph * tmppar = this;
1576 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1577 tmppar = tmppar->previous;
1580 Assert(false); // let's get an abort then
1581 return this; // This should never happen!
1587 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1591 LyXParagraph const * tmppar = this;
1593 while (tmppar && (tmppar->IsDummy()
1594 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1595 tmppar = tmppar->previous;
1598 Assert(false); // let's get an abort then
1599 return this; // This should never happen!
1605 // This function is able to hide closed footnotes.
1606 LyXParagraph * LyXParagraph::Previous()
1608 LyXParagraph * tmp = previous;
1613 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1614 tmp = tmp->previous;
1616 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1617 tmp = tmp->previous;
1618 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1619 return tmp->next->Previous();
1628 // This function is able to hide closed footnotes.
1629 LyXParagraph const * LyXParagraph::Previous() const
1631 LyXParagraph * tmp = previous;
1636 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1637 tmp = tmp->previous;
1639 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1640 tmp = tmp->previous;
1641 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1642 return tmp->next->Previous();
1651 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1654 size_type i, pos_end, pos_first;
1655 // create a new paragraph
1656 LyXParagraph * par = ParFromPos(pos);
1657 LyXParagraph * firstpar = FirstPhysicalPar();
1659 LyXParagraph * tmp = new LyXParagraph(par);
1661 tmp->footnoteflag = footnoteflag;
1662 tmp->footnotekind = footnotekind;
1664 // this is an idea for a more userfriendly layout handling, I will
1665 // see what the users say
1667 // layout stays the same with latex-environments
1669 tmp->SetOnlyLayout(firstpar->layout);
1670 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1673 if (Last() > pos || !Last() || flag == 2) {
1674 tmp->SetOnlyLayout(firstpar->layout);
1675 tmp->align = firstpar->align;
1676 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1678 tmp->line_bottom = firstpar->line_bottom;
1679 firstpar->line_bottom = false;
1680 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1681 firstpar->pagebreak_bottom = false;
1682 tmp->added_space_bottom = firstpar->added_space_bottom;
1683 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1685 tmp->depth = firstpar->depth;
1686 tmp->noindent = firstpar->noindent;
1688 // copy everything behind the break-position
1689 // to the new paragraph
1691 while (ParFromPos(pos_first) != par)
1694 pos_end = pos_first + par->text.size() - 1;
1695 // The constructor has already reserved 500 elements
1696 //if (pos_end > pos)
1697 // tmp->text.reserve(pos_end - pos);
1699 for (i = pos; i <= pos_end; i++) {
1700 par->CutIntoMinibuffer(i - pos_first);
1701 tmp->InsertFromMinibuffer(i - pos);
1703 tmp->text.resize(tmp->text.size());
1704 for (i = pos_end; i >= pos; i--)
1705 par->Erase(i - pos_first);
1707 par->text.resize(par->text.size());
1710 // just an idea of me
1712 tmp->line_top = firstpar->line_top;
1713 tmp->pagebreak_top = firstpar->pagebreak_top;
1714 tmp->added_space_top = firstpar->added_space_top;
1715 tmp->bibkey = firstpar->bibkey;
1717 // layout stays the same with latex-environments
1719 firstpar->SetOnlyLayout(tmp->layout);
1720 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1721 firstpar->depth = tmp->depth;
1727 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1729 par = par->FirstPhysicalPar();
1730 footnoteflag = par->footnoteflag;
1731 footnotekind = par->footnotekind;
1733 layout = par->layout;
1734 align = par-> align;
1735 SetLabelWidthString(par->labelwidthstring);
1737 line_bottom = par->line_bottom;
1738 pagebreak_bottom = par->pagebreak_bottom;
1739 added_space_bottom = par->added_space_bottom;
1741 line_top = par->line_top;
1742 pagebreak_top = par->pagebreak_top;
1743 added_space_top = par->added_space_top;
1745 pextra_type = par->pextra_type;
1746 pextra_width = par->pextra_width;
1747 pextra_widthp = par->pextra_widthp;
1748 pextra_alignment = par->pextra_alignment;
1749 pextra_hfill = par->pextra_hfill;
1750 pextra_start_minipage = par->pextra_start_minipage;
1752 noindent = par->noindent;
1757 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1759 LyXParagraph * tmppar = this;
1762 && tmppar->previous->footnoteflag ==
1763 LyXParagraph::CLOSED_FOOTNOTE)
1764 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1765 tmppar = tmppar->previous;
1768 return this; // This should never happen!
1774 LyXParagraph * LyXParagraph::Clone() const
1776 // create a new paragraph
1777 LyXParagraph * result = new LyXParagraph;
1779 result->MakeSameLayout(this);
1781 // this is because of the dummy layout of the paragraphs that
1783 result->layout = layout;
1785 /* table stuff -- begin*/
1787 result->table = table->Clone();
1790 /* table stuff -- end*/
1793 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1796 // copy everything behind the break-position to the new paragraph
1798 for (size_type i = 0; i < size(); i++) {
1799 CopyIntoMinibuffer(i);
1800 result->InsertFromMinibuffer(i);
1802 result->text.resize(result->text.size());
1807 bool LyXParagraph::HasSameLayout(LyXParagraph const * par)
1809 par = par->FirstPhysicalPar();
1812 par->footnoteflag == footnoteflag &&
1813 par->footnotekind == footnotekind &&
1815 par->layout == layout &&
1817 par->align == align &&
1819 par->line_bottom == line_bottom &&
1820 par->pagebreak_bottom == pagebreak_bottom &&
1821 par->added_space_bottom == added_space_bottom &&
1823 par->line_top == line_top &&
1824 par->pagebreak_top == pagebreak_top &&
1825 par->added_space_top == added_space_top &&
1827 par->pextra_type == pextra_type &&
1828 par->pextra_width == pextra_width &&
1829 par->pextra_widthp == pextra_widthp &&
1830 par->pextra_alignment == pextra_alignment &&
1831 par->pextra_hfill == pextra_hfill &&
1832 par->pextra_start_minipage == pextra_start_minipage &&
1834 par->table == table && // what means: NO TABLE AT ALL
1836 par->noindent == noindent &&
1837 par->depth == depth);
1841 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1843 // create a new paragraph
1844 LyXParagraph * par = ParFromPos(pos);
1846 LyXParagraph * tmp = new LyXParagraph(par);
1848 tmp->MakeSameLayout(par);
1850 // When can pos < Last()?
1851 // I guess pos == Last() is possible.
1853 // copy everything behind the break-position to the new
1855 size_type pos_first = 0;
1856 while (ParFromPos(pos_first) != par)
1858 size_type pos_end = pos_first + par->text.size() - 1;
1859 // make sure there is enough memory for the now larger
1860 // paragraph. This is not neccessary, because
1861 // InsertFromMinibuffer will enlarge the memory (it uses
1862 // InsertChar of course). But doing it by hand
1863 // is MUCH faster! (only one time, not thousend times!!)
1864 // Not needed since the constructor aleady have
1865 // reserved 500 elements in text.
1866 //if (pos_end > pos)
1867 // tmp->text.reserve(pos_end - pos);
1869 for (size_type i = pos; i <= pos_end; ++i) {
1870 par->CutIntoMinibuffer(i - pos_first);
1871 tmp->InsertFromMinibuffer(i - pos);
1873 tmp->text.resize(tmp->text.size());
1874 for (size_type i = pos_end; i >= pos; --i)
1875 par->Erase(i - pos_first);
1877 par->text.resize(par->text.size());
1882 // Be carefull, this does not make any check at all.
1883 void LyXParagraph::PasteParagraph()
1885 // copy the next paragraph to this one
1886 LyXParagraph * the_next = Next();
1888 LyXParagraph * firstpar = FirstPhysicalPar();
1890 // first the DTP-stuff
1891 firstpar->line_bottom = the_next->line_bottom;
1892 firstpar->added_space_bottom = the_next->added_space_bottom;
1893 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1895 size_type pos_end = the_next->text.size() - 1;
1896 size_type pos_insert = Last();
1899 // ok, now copy the paragraph
1900 for (i = 0; i <= pos_end; i++) {
1901 the_next->CutIntoMinibuffer(i);
1902 InsertFromMinibuffer(pos_insert + i);
1905 // delete the next paragraph
1910 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1912 LyXParagraph * par = ParFromPos(pos);
1914 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1915 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1921 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1923 LyXParagraph * par = ParFromPos(pos);
1925 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1926 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1932 LyXTextClass::LayoutList::size_type LyXParagraph::GetLayout() const
1934 return FirstPhysicalPar()->layout;
1938 char LyXParagraph::GetDepth() const
1940 return FirstPhysicalPar()->depth;
1944 char LyXParagraph::GetAlign() const
1946 return FirstPhysicalPar()->align;
1950 string LyXParagraph::GetLabestring() const
1952 return FirstPhysicalPar()->labelstring;
1956 int LyXParagraph::GetFirstCounter(int i) const
1958 return FirstPhysicalPar()->counter_[i];
1962 // the next two functions are for the manual labels
1963 string LyXParagraph::GetLabelWidthString() const
1965 if (!FirstPhysicalPar()->labelwidthstring.empty())
1966 return FirstPhysicalPar()->labelwidthstring;
1968 return _("Senseless with this layout!");
1972 void LyXParagraph::SetLabelWidthString(string const & s)
1974 LyXParagraph * par = FirstPhysicalPar();
1976 par->labelwidthstring = s;
1980 void LyXParagraph::SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout)
1982 LyXParagraph * par = FirstPhysicalPar();
1983 LyXParagraph * ppar = 0;
1984 LyXParagraph * npar = 0;
1986 par->layout = new_layout;
1987 /* table stuff -- begin*/
1990 /* table stuff -- end*/
1991 if (par->pextra_type == PEXTRA_NONE) {
1992 if (par->Previous()) {
1993 ppar = par->Previous()->FirstPhysicalPar();
1996 && (ppar->depth > par->depth))
1997 ppar = ppar->Previous()->FirstPhysicalPar();
2000 npar = par->Next()->NextAfterFootnote();
2003 && (npar->depth > par->depth))
2004 npar = npar->Next()->NextAfterFootnote();
2006 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2008 p1 = ppar->pextra_width,
2009 p2 = ppar->pextra_widthp;
2010 ppar->SetPExtraType(ppar->pextra_type,
2011 p1.c_str(), p2.c_str());
2013 if ((par->pextra_type == PEXTRA_NONE) &&
2014 npar && (npar->pextra_type != PEXTRA_NONE)) {
2016 p1 = npar->pextra_width,
2017 p2 = npar->pextra_widthp;
2018 npar->SetPExtraType(npar->pextra_type,
2019 p1.c_str(), p2.c_str());
2025 void LyXParagraph::SetLayout(LyXTextClass::LayoutList::size_type new_layout)
2028 * par = FirstPhysicalPar(),
2032 par->layout = new_layout;
2033 par->labelwidthstring.clear();
2034 par->align = LYX_ALIGN_LAYOUT;
2035 par->added_space_top = VSpace(VSpace::NONE);
2036 par->added_space_bottom = VSpace(VSpace::NONE);
2037 /* table stuff -- begin*/
2040 /* table stuff -- end*/
2041 if (par->pextra_type == PEXTRA_NONE) {
2042 if (par->Previous()) {
2043 ppar = par->Previous()->FirstPhysicalPar();
2046 && (ppar->depth > par->depth))
2047 ppar = ppar->Previous()->FirstPhysicalPar();
2050 npar = par->Next()->NextAfterFootnote();
2053 && (npar->depth > par->depth))
2054 npar = npar->Next()->NextAfterFootnote();
2056 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2058 p1 = ppar->pextra_width,
2059 p2 = ppar->pextra_widthp;
2060 ppar->SetPExtraType(ppar->pextra_type,
2061 p1.c_str(), p2.c_str());
2063 if ((par->pextra_type == PEXTRA_NONE) &&
2064 npar && (npar->pextra_type != PEXTRA_NONE)) {
2066 p1 = npar->pextra_width,
2067 p2 = npar->pextra_widthp;
2068 npar->SetPExtraType(npar->pextra_type,
2069 p1.c_str(), p2.c_str());
2075 // if the layout of a paragraph contains a manual label, the beginning of the
2076 // main body is the beginning of the second word. This is what the par-
2077 // function returns. If the layout does not contain a label, the main
2078 // body always starts with position 0. This differentiation is necessary,
2079 // because there cannot be a newline or a blank <= the beginning of the
2080 // main body in TeX.
2082 int LyXParagraph::BeginningOfMainBody() const
2084 if (FirstPhysicalPar() != this)
2087 // Unroll the first two cycles of the loop
2088 // and remember the previous character to
2089 // remove unnecessary GetChar() calls
2092 && GetChar(i) != LyXParagraph::META_NEWLINE) {
2094 char previous_char, temp;
2096 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2097 // Yes, this ^ is supposed to be "= " not "=="
2100 && previous_char != ' '
2101 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2103 previous_char = temp;
2108 if (i == 0 && i == size() &&
2109 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2110 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2111 ++i; /* the cursor should not jump
2112 * to the main body if there
2118 LyXParagraph * LyXParagraph::DepthHook(int deth)
2120 LyXParagraph * newpar = this;
2125 newpar = newpar->FirstPhysicalPar()->Previous();
2126 } while (newpar && newpar->GetDepth() > deth
2127 && newpar->footnoteflag == footnoteflag);
2130 if (Previous() || GetDepth())
2131 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2135 return newpar->FirstPhysicalPar();
2139 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2141 LyXParagraph const * newpar = this;
2146 newpar = newpar->FirstPhysicalPar()->Previous();
2147 } while (newpar && newpar->GetDepth() > deth
2148 && newpar->footnoteflag == footnoteflag);
2151 if (Previous() || GetDepth())
2152 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2156 return newpar->FirstPhysicalPar();
2160 int LyXParagraph::AutoDeleteInsets()
2162 #ifdef NEW_INSETTABLE
2163 vector<size_type> tmpvec;
2165 for (InsetList::iterator it = insetlist.begin();
2166 it != insetlist.end(); ++it) {
2167 if ((*it).inset && (*it).inset->AutoDelete()) {
2168 tmpvec.push_back((*it).pos);
2172 for (vector<size_type>::const_iterator cit = tmpvec.begin();
2173 cit != tmpvec.end(); ++cit) {
2178 InsetTable * tmpi = insettable;
2179 InsetTable * tmpi2 = tmpi;
2185 if (tmpi2->inset->AutoDelete()) {
2190 lyxerr << "ERROR (LyXParagraph::AutoDeleteInsets): "
2191 "cannot auto-delete insets" << endl;
2199 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
2201 #ifdef NEW_INSETTABLE
2202 InsetList::iterator it2 = insetlist.end();
2203 for (InsetList::iterator it = insetlist.begin();
2204 it != insetlist.end(); ++it) {
2205 if ((*it).pos >= pos) {
2206 if (it2 != insetlist.end() || (*it).pos < (*it2).pos)
2210 if (it2 != insetlist.end()) {
2212 return (*it2).inset;
2216 InsetTable * tmpi = insettable;
2217 InsetTable * tmpi2 = 0;
2219 if (tmpi->pos >= pos) {
2220 if (!tmpi2 || tmpi->pos < tmpi2->pos)
2227 return tmpi2->inset;
2235 // returns -1 if inset not found
2236 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2239 #ifdef NEW_INSETTABLE
2240 for (InsetList::const_iterator cit = insetlist.begin();
2241 cit != insetlist.end(); ++cit) {
2242 if ((*cit).inset == inset) {
2247 InsetTable * tmpi = insettable;
2248 while (tmpi && tmpi->inset != inset) {
2251 if (tmpi && tmpi->inset)
2254 // Think about footnotes.
2255 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2256 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2258 NextAfterFootnote()->GetPositionOfInset(inset);
2260 return text.size() + 1 + further;
2266 void LyXParagraph::readSimpleWholeFile(istream & is)
2272 InsertChar(text.size(), c);
2277 LyXParagraph * LyXParagraph::TeXOnePar(string & file, TexRow & texrow,
2278 string & foot, TexRow & foot_texrow,
2281 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2282 LyXParagraph * par = next;
2283 LyXLayout const & style =
2284 textclasslist.Style(current_view->buffer()->params.textclass,
2287 bool further_blank_line = false;
2289 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2291 if (start_of_appendix) {
2292 file += "\\appendix\n";
2296 if (tex_code_break_column && style.isCommand()){
2301 if (pagebreak_top) {
2302 file += "\\newpage";
2303 further_blank_line = true;
2305 if (added_space_top.kind() != VSpace::NONE) {
2306 file += added_space_top.asLatexCommand();
2307 further_blank_line = true;
2311 file += "\\lyxline{\\" + getFont(0).latexSize() + '}';
2312 file += "\\vspace{-1\\parskip}";
2313 further_blank_line = true;
2316 if (further_blank_line){
2321 switch (style.latextype) {
2324 file += style.latexname();
2325 file += style.latexparam();
2327 case LATEX_ITEM_ENVIRONMENT:
2329 bibkey->Latex(file, false);
2333 case LATEX_LIST_ENVIRONMENT:
2340 bool need_par = SimpleTeXOnePar(file, texrow);
2342 // Spit out footnotes
2343 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2344 && par->footnoteflag != footnoteflag) {
2345 par = par->TeXFootnote(file, texrow,
2346 foot, foot_texrow, foot_count);
2347 par->SimpleTeXOnePar(file, texrow);
2351 // Make sure that \\par is done with the font of the last
2352 // character if this has another size as the default.
2353 // This is necessary because LaTeX (and LyX on the screen)
2354 // calculates the space between the baselines according
2355 // to this font. (Matthias)
2356 LyXFont font = getFont(Last()-1);
2358 if (style.resfont.size() != font.size()) {
2360 file += font.latexSize();
2364 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2365 GetLayout()).isCommand()){
2366 if (style.resfont.size() != font.size()) {
2368 file += font.latexSize();
2372 } else if (style.resfont.size() != font.size()){
2373 file += "{\\" + font.latexSize() + " \\par}";
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 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2394 && footnotekind != LyXParagraph::FOOTNOTE
2395 && footnotekind != LyXParagraph::MARGIN
2399 // don't insert this if we would be adding it
2400 // before or after a table in a float. This
2401 // little trick is needed in order to allow
2402 // use of tables in \subfigures or \subtables.
2408 further_blank_line = false;
2410 file += "\\lyxline{\\" + getFont(Last()-1).latexSize() + '}';
2411 further_blank_line = true;
2414 if (added_space_bottom.kind() != VSpace::NONE) {
2415 file += added_space_bottom.asLatexCommand();
2416 further_blank_line = true;
2419 if (pagebreak_bottom) {
2420 file += "\\newpage";
2421 further_blank_line = true;
2424 if (further_blank_line){
2429 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2430 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2435 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2440 // This one spits out the text of the paragraph
2441 bool LyXParagraph::SimpleTeXOnePar(string & file, TexRow & texrow)
2443 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2446 return SimpleTeXOneTablePar(file, texrow);
2449 size_type main_body;
2451 bool return_value = false;
2453 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass, GetLayout());
2456 // Maybe we have to create a optional argument.
2457 if (style.labeltype != LABEL_MANUAL)
2460 main_body = BeginningOfMainBody();
2462 if (main_body > 0) {
2464 basefont = getFont(-2); // Get label font
2466 basefont = getFont(-1); // Get layout font
2474 if (style.isCommand()) {
2477 } else if (align != LYX_ALIGN_LAYOUT) {
2480 return_value = true;
2484 // Which font is currently active?
2485 LyXFont running_font = basefont;
2486 // Do we have an open font change?
2487 bool open_font = false;
2489 texrow.start(this, 0);
2491 for (size_type i = 0; i < size(); ++i) {
2493 // First char in paragraph or after label?
2494 if (i == main_body && !IsDummy()) {
2495 if (main_body > 0) {
2497 column += running_font.latexWriteEndChanges(file, basefont);
2500 basefont = getFont(-1); // Now use the layout font
2501 running_font = basefont;
2505 if (style.isCommand()) {
2508 } else if (align != LYX_ALIGN_LAYOUT) {
2511 return_value = true;
2515 file += "\\noindent ";
2519 case LYX_ALIGN_NONE:
2520 case LYX_ALIGN_BLOCK:
2521 case LYX_ALIGN_LAYOUT:
2522 case LYX_ALIGN_SPECIAL: break;
2523 case LYX_ALIGN_LEFT:
2524 file += "\\raggedright ";
2527 case LYX_ALIGN_RIGHT:
2528 file += "\\raggedleft ";
2531 case LYX_ALIGN_CENTER:
2532 file += "\\centering ";
2540 // Fully instantiated font
2541 LyXFont font = getFont(i);
2543 // Spaces at end of font change are simulated to be
2544 // outside font change, i.e. we write "\textXX{text} "
2545 // rather than "\textXX{text }". (Asger)
2546 if (open_font && c == ' ' && i <= size() - 2
2547 && !getFont(i+1).equalExceptLatex(running_font)
2548 && !getFont(i+1).equalExceptLatex(font)) {
2549 font = getFont(i + 1);
2551 // We end font definition before blanks
2552 if (!font.equalExceptLatex(running_font) && open_font) {
2553 column += running_font.latexWriteEndChanges(file,
2555 running_font = basefont;
2559 // Blanks are printed before start of fontswitch
2561 // Do not print the separation of the optional argument
2562 if (i != main_body - 1) {
2563 SimpleTeXBlanks(file, texrow, i,
2564 column, font, style);
2568 // Do we need to change font?
2569 if (!font.equalExceptLatex(running_font)
2570 && i != main_body-1) {
2571 column += font.latexWriteStartChanges(file, basefont);
2572 running_font = font;
2576 if (c == LyXParagraph::META_NEWLINE) {
2577 // newlines are handled differently here than
2578 // the default in SimpleTeXSpecialChars().
2579 if (!style.newline_allowed
2580 || font.latex() == LyXFont::ON) {
2584 column += running_font.latexWriteEndChanges(file, basefont);
2587 basefont = getFont(-1);
2588 running_font = basefont;
2589 if (font.family() ==
2590 LyXFont::TYPEWRITER_FAMILY) {
2596 texrow.start(this, i + 1);
2599 SimpleTeXSpecialChars(file, texrow,
2600 font, running_font, basefont,
2601 open_font, style, i, column, c);
2605 // If we have an open font definition, we have to close it
2607 running_font.latexWriteEndChanges(file, basefont);
2610 // Needed if there is an optional argument but no contents.
2611 if (main_body > 0 && main_body == size()) {
2613 return_value = false;
2616 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2617 return return_value;
2621 // This one spits out the text of a table paragraph
2622 bool LyXParagraph::SimpleTeXOneTablePar(string & file, TexRow & texrow)
2624 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2626 bool return_value = false;
2628 LyXLayout const & style =
2629 textclasslist.Style(current_view->buffer()->params.textclass,
2633 if (!IsDummy()) { // it is dummy if it is in a float!!!
2634 if (style.isCommand()) {
2637 } else if (align != LYX_ALIGN_LAYOUT) {
2640 return_value = true;
2643 file += "\\noindent ";
2647 case LYX_ALIGN_NONE:
2648 case LYX_ALIGN_BLOCK:
2649 case LYX_ALIGN_LAYOUT:
2650 case LYX_ALIGN_SPECIAL: break;
2651 case LYX_ALIGN_LEFT:
2652 file += "\\raggedright ";
2655 case LYX_ALIGN_RIGHT:
2656 file += "\\raggedleft ";
2659 case LYX_ALIGN_CENTER:
2660 file += "\\centering ";
2666 LyXFont basefont = getFont(-1); // Get layout font
2667 // Which font is currently active?
2668 LyXFont running_font = basefont;
2669 // Do we have an open font change?
2670 bool open_font = false;
2671 int current_cell_number = -1;
2672 int tmp = table->TexEndOfCell(file, current_cell_number);
2673 for (; tmp > 0 ; --tmp)
2676 texrow.start(this, 0);
2678 for (size_type i = 0; i < size(); ++i) {
2679 char c = GetChar(i);
2680 if (table->IsContRow(current_cell_number+1)) {
2681 if (c == LyXParagraph::META_NEWLINE)
2682 current_cell_number++;
2687 // Fully instantiated font
2688 LyXFont font = getFont(i);
2690 // Spaces at end of font change are simulated to be
2691 // outside font change.
2692 // i.e. we write "\textXX{text} " rather than
2693 // "\textXX{text }". (Asger)
2694 if (open_font && c == ' ' && i <= size() - 2
2695 && getFont(i+1) != running_font && getFont(i+1) != font) {
2696 font = getFont(i+1);
2699 // We end font definition before blanks
2700 if (font != running_font && open_font) {
2701 column += running_font.latexWriteEndChanges(file,
2703 running_font = basefont;
2706 // Blanks are printed before start of fontswitch
2708 SimpleTeXBlanks(file, texrow, i, column, font, style);
2710 // Do we need to change font?
2711 if (font != running_font) {
2712 column += font.latexWriteStartChanges(file, basefont);
2713 running_font = font;
2716 // Do we need to turn on LaTeX mode?
2717 if (font.latex() != running_font.latex()) {
2718 if (font.latex() == LyXFont::ON
2719 && style.needprotect) {
2720 file += "\\protect ";
2724 if (c == LyXParagraph::META_NEWLINE) {
2725 // special case for inside a table
2726 // different from default case in
2727 // SimpleTeXSpecialChars()
2729 column += running_font
2730 .latexWriteEndChanges(file, basefont);
2733 basefont = getFont(-1);
2734 running_font = basefont;
2735 current_cell_number++;
2736 if (table->CellHasContRow(current_cell_number) >= 0) {
2737 TeXContTableRows(file, i+1,
2738 current_cell_number,
2741 // if this cell follow only ContRows till end don't
2742 // put the EndOfCell because it is put after the
2744 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2745 current_cell_number--;
2748 int tmp = table->TexEndOfCell(file,
2749 current_cell_number);
2752 } else if (tmp < 0) {
2758 texrow.start(this, i+1);
2760 SimpleTeXSpecialChars(file, texrow,
2761 font, running_font, basefont,
2762 open_font, style, i, column, c);
2766 // If we have an open font definition, we have to close it
2768 running_font.latexWriteEndChanges(file, basefont);
2770 current_cell_number++;
2771 tmp = table->TexEndOfCell(file, current_cell_number);
2772 for (; tmp > 0; --tmp)
2774 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2775 return return_value;
2779 // This one spits out the text off ContRows in tables
2780 bool LyXParagraph::TeXContTableRows(string & file,
2781 LyXParagraph::size_type i,
2782 int current_cell_number,
2783 int & column, TexRow & texrow)
2785 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2791 bool return_value = false;
2792 LyXLayout const & style =
2793 textclasslist.Style(current_view->buffer()->params.textclass,
2795 LyXFont basefont = getFont(-1); // Get layout font
2796 // Which font is currently active?
2797 LyXFont running_font = basefont;
2798 // Do we have an open font change?
2799 bool open_font = false;
2801 size_type lastpos = i;
2802 int cell = table->CellHasContRow(current_cell_number);
2803 ++current_cell_number;
2805 // first find the right position
2807 for (; (i < size()) && (current_cell_number<cell); ++i) {
2809 if (c == LyXParagraph::META_NEWLINE)
2810 current_cell_number++;
2814 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2818 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2823 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2827 // Fully instantiated font
2828 LyXFont font = getFont(i);
2830 // Spaces at end of font change are simulated to
2831 // be outside font change. i.e. we write
2832 // "\textXX{text} " rather than "\textXX{text }".
2834 if (open_font && c == ' ' && i <= size() - 2
2835 && getFont(i + 1) != running_font
2836 && getFont(i + 1) != font) {
2837 font = getFont(i + 1);
2840 // We end font definition before blanks
2841 if (font != running_font && open_font) {
2842 column += running_font.latexWriteEndChanges(file, basefont);
2843 running_font = basefont;
2846 // Blanks are printed before start of fontswitch
2848 SimpleTeXBlanks(file, texrow, i,
2849 column, font, style);
2851 // Do we need to change font?
2852 if (font != running_font) {
2854 font.latexWriteStartChanges(file,
2856 running_font = font;
2859 // Do we need to turn on LaTeX mode?
2860 if (font.latex() != running_font.latex()) {
2861 if (font.latex() == LyXFont::ON
2862 && style.needprotect)
2864 file += "\\protect ";
2868 SimpleTeXSpecialChars(file, texrow, font,
2869 running_font, basefont,
2870 open_font, style, i, column, c);
2872 // If we have an open font definition, we have to close it
2874 running_font.latexWriteEndChanges(file, basefont);
2877 basefont = getFont(-1);
2878 running_font = basefont;
2879 cell = table->CellHasContRow(current_cell_number);
2881 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2882 return return_value;
2886 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2888 bool retval = false;
2890 case LyXParagraph::META_HFILL:
2891 sgml_string.clear();
2893 case LyXParagraph::META_PROTECTED_SEPARATOR:
2896 case LyXParagraph::META_NEWLINE:
2900 sgml_string = "&";
2903 sgml_string = "<";
2906 sgml_string = ">";
2909 sgml_string = "$";
2912 sgml_string = "#";
2915 sgml_string = "%";
2918 sgml_string = "[";
2921 sgml_string = "]";
2924 sgml_string = "{";
2927 sgml_string = "}";
2930 sgml_string = "˜";
2933 sgml_string = """;
2936 sgml_string = "\";
2942 case '\0': // Ignore :-)
2943 sgml_string.clear();
2953 void LyXParagraph::SimpleDocBookOneTablePar(string & file, string & extra,
2954 int & desc_on, int depth)
2957 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2959 LyXFont font1, font2;
2962 size_type main_body;
2963 string emph = "emphasis";
2964 bool emph_flag = false;
2966 LyXLayout const & style =
2967 textclasslist.Style(current_view->buffer()->params.textclass,
2970 if (style.labeltype != LABEL_MANUAL)
2973 main_body = BeginningOfMainBody();
2975 // Gets paragraph main font.
2977 font1 = style.labelfont;
2981 int char_line_count = depth;
2982 addNewlineAndDepth(file, depth);
2983 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2984 file += "<INFORMALTABLE>";
2985 addNewlineAndDepth(file, ++depth);
2987 int current_cell_number = -1;
2988 int tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
2990 // Parsing main loop.
2991 for (size_type i = 0; i < size(); ++i) {
2993 if (table->IsContRow(current_cell_number+1)) {
2994 if (c == LyXParagraph::META_NEWLINE)
2995 ++current_cell_number;
3000 // Fully instantiated font
3003 // Handle <emphasis> tag.
3004 if (font1.emph() != font2.emph() && i) {
3005 if (font2.emph() == LyXFont::ON) {
3006 file += "<emphasis>";
3008 } else if (emph_flag) {
3009 file += "</emphasis>";
3013 if (c == LyXParagraph::META_NEWLINE) {
3014 // We have only to control for emphasis open here!
3016 file += "</emphasis>";
3019 font1 = font2 = getFont(-1);
3020 current_cell_number++;
3021 if (table->CellHasContRow(current_cell_number) >= 0) {
3022 DocBookContTableRows(file, extra, desc_on, i+1,
3023 current_cell_number,
3026 // if this cell follow only ContRows till end don't
3027 // put the EndOfCell because it is put after the
3029 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3030 current_cell_number--;
3033 tmp= table->DocBookEndOfCell(file, current_cell_number,
3038 } else if (c == LyXParagraph::META_INSET) {
3039 inset = GetInset(i);
3041 inset->DocBook(tmp_out);
3043 // This code needs some explanation:
3044 // Two insets are treated specially
3045 // label if it is the first element in a
3046 // command paragraph
3048 // graphics inside tables or figure floats
3050 // title (the equivalente in latex for this
3052 // and title should come first
3055 if(desc_on != 3 || i != 0) {
3056 if(tmp_out[0] == '@') {
3058 extra += frontStrip(tmp_out,
3061 file += frontStrip(tmp_out,
3066 } else if (font2.latex() == LyXFont::ON) {
3067 // "TeX"-Mode on == > SGML-Mode on.
3073 if (linuxDocConvertChar(c, sgml_string)
3074 && !style.free_spacing) {
3075 // in freespacing mode, spaces are
3076 // non-breaking characters
3081 file += "</term><listitem><para>";
3087 file += sgml_string;
3093 // Needed if there is an optional argument but no contents.
3094 if (main_body > 0 && main_body == size()) {
3099 file += "</emphasis>";
3102 ++current_cell_number;
3103 tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
3104 // Resets description flag correctly.
3107 // <term> not closed...
3111 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3112 file += "</INFORMALTABLE>";
3114 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3119 void LyXParagraph::DocBookContTableRows(string & file, string & extra,
3121 LyXParagraph::size_type i,
3122 int current_cell_number, int &column)
3127 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3132 string emph= "emphasis";
3133 bool emph_flag= false;
3134 int char_line_count= 0;
3136 LyXLayout const & style =
3137 textclasslist.Style(current_view->buffer()->params.textclass,
3140 size_type main_body;
3141 if (style.labeltype != LABEL_MANUAL)
3144 main_body = BeginningOfMainBody();
3146 // Gets paragraph main font.
3149 font1 = style.labelfont;
3153 size_type lastpos = i;
3154 int cell = table->CellHasContRow(current_cell_number);
3155 ++current_cell_number;
3157 // first find the right position
3159 for (; i < size() && current_cell_number < cell; ++i) {
3161 if (c == LyXParagraph::META_NEWLINE)
3162 current_cell_number++;
3166 // I don't know how to handle this so I comment it
3167 // for the moment (Jug)
3168 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3169 // file += " \\\\\n";
3172 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3177 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3181 // Fully instantiated font
3184 // Handle <emphasis> tag.
3185 if (font1.emph() != font2.emph() && i) {
3186 if (font2.emph() == LyXFont::ON) {
3187 file += "<emphasis>";
3189 } else if (emph_flag) {
3190 file += "</emphasis>";
3194 if (c == LyXParagraph::META_INSET) {
3195 inset = GetInset(i);
3197 inset->DocBook(tmp_out);
3199 // This code needs some explanation:
3200 // Two insets are treated specially
3201 // label if it is the first element in a
3202 // command paragraph
3204 // graphics inside tables or figure floats
3205 // can't go on title (the equivalente in
3206 // latex for this case is caption and title
3207 // should come first
3210 if(desc_on != 3 || i != 0) {
3211 if(tmp_out[0] == '@') {
3213 extra += frontStrip(tmp_out, '@');
3215 file += frontStrip(tmp_out, '@');
3219 } else if (font2.latex() == LyXFont::ON) {
3220 // "TeX"-Mode on == > SGML-Mode on.
3226 if (linuxDocConvertChar(c, sgml_string)
3227 && !style.free_spacing) {
3228 // in freespacing mode, spaces are
3229 // non-breaking characters
3234 file += "</term><listitem><para>";
3240 file += sgml_string;
3244 // we have only to control for emphasis open here!
3246 file += "</emphasis>";
3249 font1 = font2 = getFont(-1);
3250 cell = table->CellHasContRow(current_cell_number);
3252 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3256 void LyXParagraph::SimpleTeXBlanks(string & file, TexRow & texrow,
3257 LyXParagraph::size_type const i,
3258 int & column, LyXFont const & font,
3259 LyXLayout const & style)
3261 if (column > tex_code_break_column
3263 && GetChar(i - 1) != ' '
3265 // In LaTeX mode, we don't want to
3266 // break lines since some commands
3268 && ! (font.latex() == LyXFont::ON)
3269 // same in FreeSpacing mode
3270 && !style.free_spacing
3271 // In typewriter mode, we want to avoid
3272 // ! . ? : at the end of a line
3273 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3274 && (GetChar(i-1) == '.'
3275 || GetChar(i-1) == '?'
3276 || GetChar(i-1) == ':'
3277 || GetChar(i-1) == '!'))) {
3278 if (tex_code_break_column == 0) {
3279 // in batchmode we need LaTeX to still
3280 // see it as a space not as an extra '\n'
3286 texrow.start(this, i+1);
3288 } else if (font.latex() == LyXFont::OFF) {
3289 if (style.free_spacing) {
3298 void LyXParagraph::SimpleTeXSpecialChars(string & file, TexRow & texrow,
3300 LyXFont & running_font,
3303 LyXLayout const & style,
3304 LyXParagraph::size_type & i,
3305 int & column, char const c)
3307 // Two major modes: LaTeX or plain
3308 // Handle here those cases common to both modes
3309 // and then split to handle the two modes separately.
3311 case LyXParagraph::META_INSET: {
3312 Inset * inset = GetInset(i);
3314 int len = file.length();
3315 int tmp = inset->Latex(file, style.isCommand());
3320 column += file.length() - len;
3329 case LyXParagraph::META_NEWLINE:
3331 column += running_font.latexWriteEndChanges(file,
3335 basefont = getFont(-1);
3336 running_font = basefont;
3339 case LyXParagraph::META_HFILL:
3340 file += "\\hfill{}";
3345 // And now for the special cases within each mode
3346 // Are we in LaTeX mode?
3347 if (font.latex() == LyXFont::ON) {
3348 // at present we only have one option
3349 // but I'll leave it as a switch statement
3350 // so its simpler to extend. (ARRae)
3352 case LyXParagraph::META_PROTECTED_SEPARATOR:
3357 // make sure that we will not print
3358 // error generating chars to the tex
3359 // file. This test would not be needed
3360 // if it were done in the buffer
3368 // Plain mode (i.e. not LaTeX)
3370 case LyXParagraph::META_PROTECTED_SEPARATOR:
3375 file += "\\textbackslash{}";
3379 case '°': case '±': case '²': case '³':
3380 case '×': case '÷': case '¹': case 'ª':
3381 case 'º': case '¬': case 'µ':
3382 if (current_view->buffer()->params.inputenc == "latin1") {
3383 file += "\\ensuremath{";
3392 case '|': case '<': case '>':
3393 // In T1 encoding, these characters exist
3394 if (lyxrc->fontenc == "T1") {
3396 //... but we should avoid ligatures
3397 if ((c == '>' || c == '<')
3399 && GetChar(i+1) == c){
3400 file += "\\textcompwordmark{}";
3405 // Typewriter font also has them
3406 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3410 // Otherwise, we use what LaTeX
3414 file += "\\textless{}";
3418 file += "\\textgreater{}";
3422 file += "\\textbar{}";
3428 case '-': // "--" in Typewriter mode -> "-{}-"
3430 && GetChar(i + 1) == '-'
3431 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3440 file += "\\char`\\\"{}";
3445 if (current_view->buffer()->params.inputenc == "default") {
3446 file += "\\pounds{}";
3454 case '%': case '#': case '{':
3462 file += "\\textasciitilde{}";
3467 file += "\\textasciicircum{}";
3471 case '*': case '[': case ']':
3472 // avoid being mistaken for optional arguments
3480 // Blanks are printed before font switching.
3481 // Sure? I am not! (try nice-latex)
3482 // I am sure it's correct. LyX might be smarter
3483 // in the future, but for now, nothing wrong is
3488 /* idea for labels --- begin*/
3492 && font.family() != LyXFont::TYPEWRITER_FAMILY
3493 && GetChar(i + 1) == 'y'
3494 && GetChar(i + 2) == 'X') {
3502 && font.family() != LyXFont::TYPEWRITER_FAMILY
3503 && GetChar(i + 1) == 'e'
3504 && GetChar(i + 2) == 'X') {
3509 // Check for "LaTeX2e"
3512 && font.family() != LyXFont::TYPEWRITER_FAMILY
3513 && GetChar(i + 1) == 'a'
3514 && GetChar(i + 2) == 'T'
3515 && GetChar(i + 3) == 'e'
3516 && GetChar(i + 4) == 'X'
3517 && GetChar(i + 5) == '2'
3518 && GetChar(i + 6) == 'e') {
3519 file += "\\LaTeXe{}";
3523 // Check for "LaTeX"
3526 && font.family() != LyXFont::TYPEWRITER_FAMILY
3527 && GetChar(i + 1) == 'a'
3528 && GetChar(i + 2) == 'T'
3529 && GetChar(i + 3) == 'e'
3530 && GetChar(i + 4) == 'X') {
3531 file += "\\LaTeX{}";
3534 /* idea for labels --- end*/
3535 } else if (c != '\0') {
3545 bool LyXParagraph::RoffContTableRows(ostream & os,
3546 LyXParagraph::size_type i,
3552 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3557 string fname2 = TmpFileName(string(), "RAT2");
3559 int cell = table->CellHasContRow(actcell);
3562 // first find the right position
3564 for (; i < size() && actcell < cell; ++i) {
3566 if (c == LyXParagraph::META_NEWLINE)
3571 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3574 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3576 font2 = GetFontSettings(i);
3577 if (font1.latex() != font2.latex()) {
3578 if (font2.latex() != LyXFont::OFF)
3583 case LyXParagraph::META_INSET:
3584 if ((inset = GetInset(i))) {
3585 fstream fs(fname2.c_str(),
3588 WriteAlert(_("LYX_ERROR:"),
3589 _("Cannot open temporary file:"),
3593 inset->Latex(fs, -1);
3606 case LyXParagraph::META_NEWLINE:
3608 case LyXParagraph::META_HFILL:
3610 case LyXParagraph::META_PROTECTED_SEPARATOR:
3619 lyxerr.debug() << "RoffAsciiTable: "
3620 "NULL char in structure."
3625 cell = table->CellHasContRow(actcell);
3631 LyXParagraph * LyXParagraph::TeXDeeper(string & file, TexRow & texrow,
3632 string & foot, TexRow & foot_texrow,
3635 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3636 LyXParagraph * par = this;
3638 while (par && par->depth == depth) {
3640 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3641 if (textclasslist.Style(current_view->buffer()->params.textclass,
3642 par->layout).isEnvironment()
3643 || par->pextra_type != PEXTRA_NONE)
3645 par = par->TeXEnvironment(file, texrow,
3649 par = par->TeXOnePar(file, texrow,
3654 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3660 LyXParagraph * LyXParagraph::TeXEnvironment(string & file, TexRow & texrow,
3662 TexRow & foot_texrow,
3665 bool eindent_open = false;
3666 bool foot_this_level = false;
3667 // flags when footnotetext should be appended to file.
3668 static bool minipage_open = false;
3669 static int minipage_open_depth = 0;
3670 char par_sep = current_view->buffer()->params.paragraph_separation;
3672 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3674 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3676 LyXLayout const & style =
3677 textclasslist.Style(current_view->buffer()->params.textclass,
3680 if (pextra_type == PEXTRA_INDENT) {
3681 if (!pextra_width.empty()) {
3682 file += "\\begin{LyXParagraphIndent}{"
3683 + pextra_width + "}\n";
3685 //float ib = atof(pextra_widthp.c_str())/100;
3686 // string can't handle floats at present (971109)
3687 // so I'll do a conversion by hand knowing that
3688 // the limits are 0.0 to 1.0. ARRae.
3689 file += "\\begin{LyXParagraphIndent}{";
3690 switch (pextra_widthp.length()) {
3696 file += pextra_widthp;
3700 file += pextra_widthp;
3702 file += "\\columnwidth}\n";
3705 eindent_open = true;
3707 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3708 if (pextra_hfill && Previous() &&
3709 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3710 file += "\\hfill{}\n";
3713 if (par_sep == BufferParams::PARSEP_INDENT) {
3714 file += "{\\setlength\\parindent{0pt}\n";
3717 file += "\\begin{minipage}";
3718 switch(pextra_alignment) {
3719 case MINIPAGE_ALIGN_TOP:
3722 case MINIPAGE_ALIGN_MIDDLE:
3725 case MINIPAGE_ALIGN_BOTTOM:
3729 if (!pextra_width.empty()) {
3731 file += pextra_width + "}\n";
3733 //float ib = atof(par->pextra_width.c_str())/100;
3734 // string can't handle floats at present
3735 // so I'll do a conversion by hand knowing that
3736 // the limits are 0.0 to 1.0. ARRae.
3738 switch (pextra_widthp.length()) {
3744 file += pextra_widthp;
3748 file += pextra_widthp;
3750 file += "\\columnwidth}\n";
3753 if (par_sep == BufferParams::PARSEP_INDENT) {
3754 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3757 minipage_open = true;
3758 minipage_open_depth = depth;
3761 #ifdef WITH_WARNINGS
3762 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3763 //I disabled it because it breaks when lists span on several
3766 if (style.isEnvironment()){
3767 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3768 #ifdef FANCY_FOOTNOTE_CODE
3769 if (foot_count < 0) {
3770 // flag that footnote[mark][text] should be
3771 // used for any footnotes from now on
3773 foot_this_level = true;
3776 file += "\\begin{" + style.latexname() + "}{"
3777 + labelwidthstring + "}\n";
3778 } else if (style.labeltype == LABEL_BIBLIO) {
3780 file += "\\begin{" + style.latexname() + "}{"
3781 + bibitemWidthest() + "}\n";
3782 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3783 #ifdef FANCY_FOOTNOTE_CODE
3784 if (foot_count < 0) {
3785 // flag that footnote[mark][text] should be
3786 // used for any footnotes from now on
3788 foot_this_level = true;
3791 file += "\\begin{" + style.latexname() + '}'
3792 + style.latexparam() + '\n';
3794 file += "\\begin{" + style.latexname() + '}'
3795 + style.latexparam() + '\n';
3798 LyXParagraph * par = this;
3800 par = par->TeXOnePar(file, texrow,
3801 foot, foot_texrow, foot_count);
3803 if (minipage_open && par && !style.isEnvironment() &&
3804 (par->pextra_type == PEXTRA_MINIPAGE) &&
3805 par->pextra_start_minipage) {
3806 file += "\\end{minipage}\n";
3808 if (par_sep == BufferParams::PARSEP_INDENT) {
3812 minipage_open = false;
3814 if (par && par->depth > depth) {
3815 if (textclasslist.Style(current_view->buffer()->params.textclass,
3816 par->layout).isParagraph()
3818 && !suffixIs(file, "\n\n")) {
3819 // There should be at least one '\n' already
3820 // but we need there to be two for Standard
3821 // paragraphs that are depth-increment'ed to be
3822 // output correctly. However, tables can
3823 // also be paragraphs so don't adjust them.
3828 par = par->TeXDeeper(file, texrow,
3829 foot, foot_texrow, foot_count);
3831 if (par && par->layout == layout && par->depth == depth &&
3832 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3833 if (par->pextra_hfill && par->Previous() &&
3834 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3835 file += "\\hfill{}\n";
3838 if (par_sep == BufferParams::PARSEP_INDENT) {
3839 file += "{\\setlength\\parindent{0pt}\n";
3842 file += "\\begin{minipage}";
3843 switch(par->pextra_alignment) {
3844 case MINIPAGE_ALIGN_TOP:
3847 case MINIPAGE_ALIGN_MIDDLE:
3850 case MINIPAGE_ALIGN_BOTTOM:
3854 if (!par->pextra_width.empty()) {
3856 file += par->pextra_width;
3859 //float ib = atof(par->pextra_widthp.c_str())/100;
3860 // string can't handle floats at present
3861 // so I'll do a conversion by hand knowing that
3862 // the limits are 0.0 to 1.0. ARRae.
3864 switch (par->pextra_widthp.length()) {
3870 file += par->pextra_widthp;
3874 file += par->pextra_widthp;
3876 file += "\\columnwidth}\n";
3879 if (par_sep == BufferParams::PARSEP_INDENT) {
3880 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3883 minipage_open = true;
3884 minipage_open_depth = par->depth;
3887 && par->layout == layout
3888 && par->depth == depth
3889 && par->pextra_type == pextra_type);
3891 if (style.isEnvironment()) {
3892 file += "\\end{" + style.latexname() + '}';
3893 // maybe this should go after the minipage closes?
3894 if (foot_this_level) {
3895 if (foot_count >= 1) {
3896 if (foot_count > 1) {
3897 file += "\\addtocounter{footnote}{-";
3898 file += tostr(foot_count - 1);
3902 texrow += foot_texrow;
3904 foot_texrow.reset();
3909 if (minipage_open && (minipage_open_depth == depth) &&
3910 (!par || par->pextra_start_minipage ||
3911 par->pextra_type != PEXTRA_MINIPAGE)) {
3912 file += "\\end{minipage}\n";
3914 if (par_sep == BufferParams::PARSEP_INDENT) {
3918 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3919 file += "\\medskip\n\n";
3923 minipage_open = false;
3926 file += "\\end{LyXParagraphIndent}\n";
3929 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3930 && par->pextra_hfill)) {
3934 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3935 return par; // ale970302
3939 LyXParagraph * LyXParagraph::TeXFootnote(string & file, TexRow & texrow,
3940 string & foot, TexRow & foot_texrow,
3943 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3944 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3945 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3946 "No footnote!" << endl;
3948 LyXParagraph * par = this;
3949 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass,
3950 previous->GetLayout());
3952 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3953 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3954 "Float other than footnote in command"
3955 " with moving argument is illegal" << endl;
3958 if (footnotekind != LyXParagraph::FOOTNOTE
3959 && footnotekind != LyXParagraph::MARGIN
3961 && !suffixIs(file, '\n')) {
3962 // we need to ensure that real floats like tables and figures
3963 // have their \begin{} on a new line otherwise we can get
3964 // incorrect results when using the endfloat.sty package
3965 // especially if two floats follow one another. ARRae 981022
3966 // NOTE: if the file is length 0 it must have just been
3967 // written out so we assume it ended with a '\n'
3972 BufferParams * params = ¤t_view->buffer()->params;
3973 bool footer_in_body = true;
3974 switch (footnotekind) {
3975 case LyXParagraph::FOOTNOTE:
3976 if (style.intitle) {
3977 file += "\\thanks{\n";
3978 footer_in_body = false;
3980 if (foot_count == -1) {
3981 // we're at depth 0 so we can use:
3982 file += "\\footnote{%\n";
3983 footer_in_body = false;
3985 file += "\\footnotemark{}%\n";
3987 // we only need this when there are
3988 // multiple footnotes
3989 foot += "\\stepcounter{footnote}";
3991 foot += "\\footnotetext{%\n";
3992 foot_texrow.start(this, 0);
3993 foot_texrow.newline();
3998 case LyXParagraph::MARGIN:
3999 file += "\\marginpar{\n";
4001 case LyXParagraph::FIG:
4002 if (pextra_type == PEXTRA_FLOATFLT
4003 && (!pextra_width.empty()
4004 || !pextra_widthp.empty())) {
4006 if (!pextra_width.empty())
4007 sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
4008 pextra_width.c_str());
4011 "\\begin{floatingfigure}{%f\\textwidth}\n",
4012 atoi(pextra_widthp.c_str())/100.0);
4015 file += "\\begin{figure}";
4016 if (!params->float_placement.empty()) {
4018 file += params->float_placement;
4025 case LyXParagraph::TAB:
4026 file += "\\begin{table}";
4027 if (!params->float_placement.empty()) {
4029 file += params->float_placement;
4035 case LyXParagraph::WIDE_FIG:
4036 file += "\\begin{figure*}";
4037 if (!params->float_placement.empty()) {
4039 file += params->float_placement;
4045 case LyXParagraph::WIDE_TAB:
4046 file += "\\begin{table*}";
4047 if (!params->float_placement.empty()) {
4049 file += params->float_placement;
4055 case LyXParagraph::ALGORITHM:
4056 file += "\\begin{algorithm}\n";
4061 if (footnotekind != LyXParagraph::FOOTNOTE
4062 || !footer_in_body) {
4063 // Process text for all floats except footnotes in body
4065 LyXLayout const & style =
4066 textclasslist.Style(current_view->buffer()->params.textclass,
4069 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4071 if (style.isEnvironment()
4072 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4073 // Allows the use of minipages within float
4074 // environments. Shouldn't be circular because
4075 // we don't support footnotes inside
4076 // floats (yet). ARRae
4077 par = par->TeXEnvironment(file, texrow,
4081 par = par->TeXOnePar(file, texrow,
4086 if (par && !par->IsDummy() && par->depth > depth) {
4087 par = par->TeXDeeper(file, texrow,
4091 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4093 // process footnotes > depth 0 or in environments separately
4094 // NOTE: Currently don't support footnotes within footnotes
4095 // even though that is possible using the \footnotemark
4097 TexRow dummy_texrow;
4098 int dummy_count = 0;
4100 LyXLayout const & style =
4101 textclasslist.Style(current_view->buffer()->params.textclass,
4104 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4106 if (style.isEnvironment()
4107 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4108 // Allows the use of minipages within float
4109 // environments. Shouldn't be circular because
4110 // we don't support footnotes inside
4111 // floats (yet). ARRae
4112 par = par->TeXEnvironment(foot, foot_texrow,
4113 dummy, dummy_texrow,
4116 par = par->TeXOnePar(foot, foot_texrow,
4117 dummy, dummy_texrow,
4121 if (par && !par->IsDummy() && par->depth > depth) {
4122 par = par->TeXDeeper(foot, foot_texrow,
4123 dummy, dummy_texrow,
4127 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4129 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4130 "Footnote in a Footnote -- not supported"
4135 switch (footnotekind) {
4136 case LyXParagraph::FOOTNOTE:
4137 if (footer_in_body) {
4138 // This helps tell which of the multiple
4139 // footnotetexts an error was in.
4141 foot_texrow.newline();
4146 case LyXParagraph::MARGIN:
4149 case LyXParagraph::FIG:
4150 if (pextra_type == PEXTRA_FLOATFLT
4151 && (!pextra_width.empty()
4152 || !pextra_widthp.empty()))
4153 file += "\\end{floatingfigure}";
4155 file += "\\end{figure}";
4157 case LyXParagraph::TAB:
4158 file += "\\end{table}";
4160 case LyXParagraph::WIDE_FIG:
4161 file += "\\end{figure*}";
4163 case LyXParagraph::WIDE_TAB:
4164 file += "\\end{table*}";
4166 case LyXParagraph::ALGORITHM:
4167 file += "\\end{algorithm}";
4171 if (footnotekind != LyXParagraph::FOOTNOTE
4172 && footnotekind != LyXParagraph::MARGIN) {
4173 // we need to ensure that real floats like tables and figures
4174 // have their \end{} on a line of their own otherwise we can
4175 // get incorrect results when using the endfloat.sty package.
4180 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4185 void LyXParagraph::SetPExtraType(int type, char const * width,
4186 char const * widthp)
4189 pextra_width = width;
4190 pextra_widthp = widthp;
4192 if (textclasslist.Style(current_view->buffer()->params.textclass,
4193 layout).isEnvironment()) {
4198 while (par && (par->layout == layout)
4199 && (par->depth == depth)) {
4201 par = par->Previous();
4203 par = par->FirstPhysicalPar();
4204 while (par && par->depth > depth) {
4205 par = par->Previous();
4207 par = par->FirstPhysicalPar();
4211 while (par && (par->layout == layout)
4212 && (par->depth == depth)) {
4213 par->pextra_type = type;
4214 par->pextra_width = width;
4215 par->pextra_widthp = widthp;
4216 par = par->NextAfterFootnote();
4217 if (par && (par->depth > depth))
4218 par->SetPExtraType(type, width, widthp);
4219 while (par && ((par->depth > depth) || par->IsDummy()))
4220 par = par->NextAfterFootnote();
4226 void LyXParagraph::UnsetPExtraType()
4228 if (pextra_type == PEXTRA_NONE)
4231 pextra_type = PEXTRA_NONE;
4232 pextra_width.clear();
4233 pextra_widthp.clear();
4235 if (textclasslist.Style(current_view->buffer()->params.textclass,
4236 layout).isEnvironment()) {
4241 while (par && (par->layout == layout)
4242 && (par->depth == depth)) {
4244 par = par->Previous();
4246 par = par->FirstPhysicalPar();
4247 while (par && par->depth > depth) {
4248 par = par->Previous();
4250 par = par->FirstPhysicalPar();
4254 while (par && (par->layout == layout)
4255 && (par->depth == depth)) {
4256 par->pextra_type = PEXTRA_NONE;
4257 par->pextra_width.clear();
4258 par->pextra_widthp.clear();
4259 par = par->NextAfterFootnote();
4260 if (par && (par->depth > depth))
4261 par->UnsetPExtraType();
4262 while (par && ((par->depth > depth) || par->IsDummy()))
4263 par = par->NextAfterFootnote();
4269 bool LyXParagraph::IsHfill(size_type pos) const
4271 return IsHfillChar(GetChar(pos));
4275 bool LyXParagraph::IsInset(size_type pos) const
4277 return IsInsetChar(GetChar(pos));
4281 bool LyXParagraph::IsFloat(size_type pos) const
4283 return IsFloatChar(GetChar(pos));
4287 bool LyXParagraph::IsNewline(size_type pos) const
4291 tmp = IsNewlineChar(GetChar(pos));
4296 bool LyXParagraph::IsSeparator(size_type pos) const
4298 return IsSeparatorChar(GetChar(pos));
4302 bool LyXParagraph::IsLineSeparator(size_type pos) const
4304 return IsLineSeparatorChar(GetChar(pos));
4308 bool LyXParagraph::IsKomma(size_type pos) const
4310 return IsKommaChar(GetChar(pos));
4314 /// Used by the spellchecker
4315 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4317 unsigned char c = GetChar(pos);
4318 if (IsLetterChar(c))
4320 // '\0' is not a letter, allthough every string contains "" (below)
4323 // We want to pass the ' and escape chars to ispell
4324 string extra = lyxrc->isp_esc_chars + '\'';
4328 return contains(extra, ch);
4332 bool LyXParagraph::IsWord(size_type pos ) const
4334 return IsWordChar(GetChar(pos)) ;