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;
1586 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1590 LyXParagraph const * tmppar = this;
1594 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1595 tmppar = tmppar->previous;
1604 // This function is able to hide closed footnotes.
1605 LyXParagraph * LyXParagraph::Previous()
1607 LyXParagraph * tmp = previous;
1612 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1613 tmp = tmp->previous;
1615 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1616 tmp = tmp->previous;
1617 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1618 return tmp->next->Previous();
1627 // This function is able to hide closed footnotes.
1628 LyXParagraph const * LyXParagraph::Previous() const
1630 LyXParagraph * tmp = previous;
1635 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1636 tmp = tmp->previous;
1638 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1639 tmp = tmp->previous;
1640 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1641 return tmp->next->Previous();
1650 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1653 size_type i, pos_end, pos_first;
1654 // create a new paragraph
1655 LyXParagraph * par = ParFromPos(pos);
1656 LyXParagraph * firstpar = FirstPhysicalPar();
1658 LyXParagraph * tmp = new LyXParagraph(par);
1660 tmp->footnoteflag = footnoteflag;
1661 tmp->footnotekind = footnotekind;
1663 // this is an idea for a more userfriendly layout handling, I will
1664 // see what the users say
1666 // layout stays the same with latex-environments
1668 tmp->SetOnlyLayout(firstpar->layout);
1669 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1672 if (Last() > pos || !Last() || flag == 2) {
1673 tmp->SetOnlyLayout(firstpar->layout);
1674 tmp->align = firstpar->align;
1675 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1677 tmp->line_bottom = firstpar->line_bottom;
1678 firstpar->line_bottom = false;
1679 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1680 firstpar->pagebreak_bottom = false;
1681 tmp->added_space_bottom = firstpar->added_space_bottom;
1682 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1684 tmp->depth = firstpar->depth;
1685 tmp->noindent = firstpar->noindent;
1687 // copy everything behind the break-position
1688 // to the new paragraph
1690 while (ParFromPos(pos_first) != par)
1693 pos_end = pos_first + par->text.size() - 1;
1694 // The constructor has already reserved 500 elements
1695 //if (pos_end > pos)
1696 // tmp->text.reserve(pos_end - pos);
1698 for (i = pos; i <= pos_end; i++) {
1699 par->CutIntoMinibuffer(i - pos_first);
1700 tmp->InsertFromMinibuffer(i - pos);
1702 tmp->text.resize(tmp->text.size());
1703 for (i = pos_end; i >= pos; i--)
1704 par->Erase(i - pos_first);
1706 par->text.resize(par->text.size());
1709 // just an idea of me
1711 tmp->line_top = firstpar->line_top;
1712 tmp->pagebreak_top = firstpar->pagebreak_top;
1713 tmp->added_space_top = firstpar->added_space_top;
1714 tmp->bibkey = firstpar->bibkey;
1716 // layout stays the same with latex-environments
1718 firstpar->SetOnlyLayout(tmp->layout);
1719 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1720 firstpar->depth = tmp->depth;
1726 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1728 par = par->FirstPhysicalPar();
1729 footnoteflag = par->footnoteflag;
1730 footnotekind = par->footnotekind;
1732 layout = par->layout;
1733 align = par-> align;
1734 SetLabelWidthString(par->labelwidthstring);
1736 line_bottom = par->line_bottom;
1737 pagebreak_bottom = par->pagebreak_bottom;
1738 added_space_bottom = par->added_space_bottom;
1740 line_top = par->line_top;
1741 pagebreak_top = par->pagebreak_top;
1742 added_space_top = par->added_space_top;
1744 pextra_type = par->pextra_type;
1745 pextra_width = par->pextra_width;
1746 pextra_widthp = par->pextra_widthp;
1747 pextra_alignment = par->pextra_alignment;
1748 pextra_hfill = par->pextra_hfill;
1749 pextra_start_minipage = par->pextra_start_minipage;
1751 noindent = par->noindent;
1756 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1758 LyXParagraph * tmppar = this;
1761 && tmppar->previous->footnoteflag ==
1762 LyXParagraph::CLOSED_FOOTNOTE)
1763 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1764 tmppar = tmppar->previous;
1767 return this; // This should never happen!
1773 LyXParagraph * LyXParagraph::Clone() const
1775 // create a new paragraph
1776 LyXParagraph * result = new LyXParagraph;
1778 result->MakeSameLayout(this);
1780 // this is because of the dummy layout of the paragraphs that
1782 result->layout = layout;
1784 /* table stuff -- begin*/
1786 result->table = table->Clone();
1789 /* table stuff -- end*/
1792 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1795 // copy everything behind the break-position to the new paragraph
1797 for (size_type i = 0; i < size(); i++) {
1798 CopyIntoMinibuffer(i);
1799 result->InsertFromMinibuffer(i);
1801 result->text.resize(result->text.size());
1806 bool LyXParagraph::HasSameLayout(LyXParagraph const * par)
1808 par = par->FirstPhysicalPar();
1811 par->footnoteflag == footnoteflag &&
1812 par->footnotekind == footnotekind &&
1814 par->layout == layout &&
1816 par->align == align &&
1818 par->line_bottom == line_bottom &&
1819 par->pagebreak_bottom == pagebreak_bottom &&
1820 par->added_space_bottom == added_space_bottom &&
1822 par->line_top == line_top &&
1823 par->pagebreak_top == pagebreak_top &&
1824 par->added_space_top == added_space_top &&
1826 par->pextra_type == pextra_type &&
1827 par->pextra_width == pextra_width &&
1828 par->pextra_widthp == pextra_widthp &&
1829 par->pextra_alignment == pextra_alignment &&
1830 par->pextra_hfill == pextra_hfill &&
1831 par->pextra_start_minipage == pextra_start_minipage &&
1833 par->table == table && // what means: NO TABLE AT ALL
1835 par->noindent == noindent &&
1836 par->depth == depth);
1840 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1842 // create a new paragraph
1843 LyXParagraph * par = ParFromPos(pos);
1845 LyXParagraph * tmp = new LyXParagraph(par);
1847 tmp->MakeSameLayout(par);
1849 // When can pos < Last()?
1850 // I guess pos == Last() is possible.
1852 // copy everything behind the break-position to the new
1854 size_type pos_first = 0;
1855 while (ParFromPos(pos_first) != par)
1857 size_type pos_end = pos_first + par->text.size() - 1;
1858 // make sure there is enough memory for the now larger
1859 // paragraph. This is not neccessary, because
1860 // InsertFromMinibuffer will enlarge the memory (it uses
1861 // InsertChar of course). But doing it by hand
1862 // is MUCH faster! (only one time, not thousend times!!)
1863 // Not needed since the constructor aleady have
1864 // reserved 500 elements in text.
1865 //if (pos_end > pos)
1866 // tmp->text.reserve(pos_end - pos);
1868 for (size_type i = pos; i <= pos_end; ++i) {
1869 par->CutIntoMinibuffer(i - pos_first);
1870 tmp->InsertFromMinibuffer(i - pos);
1872 tmp->text.resize(tmp->text.size());
1873 for (size_type i = pos_end; i >= pos; --i)
1874 par->Erase(i - pos_first);
1876 par->text.resize(par->text.size());
1881 // Be carefull, this does not make any check at all.
1882 void LyXParagraph::PasteParagraph()
1884 // copy the next paragraph to this one
1885 LyXParagraph * the_next = Next();
1887 LyXParagraph * firstpar = FirstPhysicalPar();
1889 // first the DTP-stuff
1890 firstpar->line_bottom = the_next->line_bottom;
1891 firstpar->added_space_bottom = the_next->added_space_bottom;
1892 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1894 size_type pos_end = the_next->text.size() - 1;
1895 size_type pos_insert = Last();
1898 // ok, now copy the paragraph
1899 for (i = 0; i <= pos_end; i++) {
1900 the_next->CutIntoMinibuffer(i);
1901 InsertFromMinibuffer(pos_insert + i);
1904 // delete the next paragraph
1909 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1911 LyXParagraph * par = ParFromPos(pos);
1913 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1914 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1920 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1922 LyXParagraph * par = ParFromPos(pos);
1924 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1925 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1931 LyXTextClass::LayoutList::size_type LyXParagraph::GetLayout() const
1933 return FirstPhysicalPar()->layout;
1937 char LyXParagraph::GetDepth() const
1939 return FirstPhysicalPar()->depth;
1943 char LyXParagraph::GetAlign() const
1945 return FirstPhysicalPar()->align;
1949 string LyXParagraph::GetLabestring() const
1951 return FirstPhysicalPar()->labelstring;
1955 int LyXParagraph::GetFirstCounter(int i) const
1957 return FirstPhysicalPar()->counter_[i];
1961 // the next two functions are for the manual labels
1962 string LyXParagraph::GetLabelWidthString() const
1964 if (!FirstPhysicalPar()->labelwidthstring.empty())
1965 return FirstPhysicalPar()->labelwidthstring;
1967 return _("Senseless with this layout!");
1971 void LyXParagraph::SetLabelWidthString(string const & s)
1973 LyXParagraph * par = FirstPhysicalPar();
1975 par->labelwidthstring = s;
1979 void LyXParagraph::SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout)
1981 LyXParagraph * par = FirstPhysicalPar();
1982 LyXParagraph * ppar = 0;
1983 LyXParagraph * npar = 0;
1985 par->layout = new_layout;
1986 /* table stuff -- begin*/
1989 /* table stuff -- end*/
1990 if (par->pextra_type == PEXTRA_NONE) {
1991 if (par->Previous()) {
1992 ppar = par->Previous()->FirstPhysicalPar();
1995 && (ppar->depth > par->depth))
1996 ppar = ppar->Previous()->FirstPhysicalPar();
1999 npar = par->Next()->NextAfterFootnote();
2002 && (npar->depth > par->depth))
2003 npar = npar->Next()->NextAfterFootnote();
2005 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2007 p1 = ppar->pextra_width,
2008 p2 = ppar->pextra_widthp;
2009 ppar->SetPExtraType(ppar->pextra_type,
2010 p1.c_str(), p2.c_str());
2012 if ((par->pextra_type == PEXTRA_NONE) &&
2013 npar && (npar->pextra_type != PEXTRA_NONE)) {
2015 p1 = npar->pextra_width,
2016 p2 = npar->pextra_widthp;
2017 npar->SetPExtraType(npar->pextra_type,
2018 p1.c_str(), p2.c_str());
2024 void LyXParagraph::SetLayout(LyXTextClass::LayoutList::size_type new_layout)
2027 * par = FirstPhysicalPar(),
2031 par->layout = new_layout;
2032 par->labelwidthstring.clear();
2033 par->align = LYX_ALIGN_LAYOUT;
2034 par->added_space_top = VSpace(VSpace::NONE);
2035 par->added_space_bottom = VSpace(VSpace::NONE);
2036 /* table stuff -- begin*/
2039 /* table stuff -- end*/
2040 if (par->pextra_type == PEXTRA_NONE) {
2041 if (par->Previous()) {
2042 ppar = par->Previous()->FirstPhysicalPar();
2045 && (ppar->depth > par->depth))
2046 ppar = ppar->Previous()->FirstPhysicalPar();
2049 npar = par->Next()->NextAfterFootnote();
2052 && (npar->depth > par->depth))
2053 npar = npar->Next()->NextAfterFootnote();
2055 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2057 p1 = ppar->pextra_width,
2058 p2 = ppar->pextra_widthp;
2059 ppar->SetPExtraType(ppar->pextra_type,
2060 p1.c_str(), p2.c_str());
2062 if ((par->pextra_type == PEXTRA_NONE) &&
2063 npar && (npar->pextra_type != PEXTRA_NONE)) {
2065 p1 = npar->pextra_width,
2066 p2 = npar->pextra_widthp;
2067 npar->SetPExtraType(npar->pextra_type,
2068 p1.c_str(), p2.c_str());
2074 // if the layout of a paragraph contains a manual label, the beginning of the
2075 // main body is the beginning of the second word. This is what the par-
2076 // function returns. If the layout does not contain a label, the main
2077 // body always starts with position 0. This differentiation is necessary,
2078 // because there cannot be a newline or a blank <= the beginning of the
2079 // main body in TeX.
2081 int LyXParagraph::BeginningOfMainBody() const
2083 if (FirstPhysicalPar() != this)
2086 // Unroll the first two cycles of the loop
2087 // and remember the previous character to
2088 // remove unnecessary GetChar() calls
2091 && GetChar(i) != LyXParagraph::META_NEWLINE) {
2093 char previous_char, temp;
2095 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2096 // Yes, this ^ is supposed to be "= " not "=="
2099 && previous_char != ' '
2100 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2102 previous_char = temp;
2107 if (i == 0 && i == size() &&
2108 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2109 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2110 ++i; /* the cursor should not jump
2111 * to the main body if there
2117 LyXParagraph * LyXParagraph::DepthHook(int deth)
2119 LyXParagraph * newpar = this;
2124 newpar = newpar->FirstPhysicalPar()->Previous();
2125 } while (newpar && newpar->GetDepth() > deth
2126 && newpar->footnoteflag == footnoteflag);
2129 if (Previous() || GetDepth())
2130 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2134 return newpar->FirstPhysicalPar();
2138 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2140 LyXParagraph const * newpar = this;
2145 newpar = newpar->FirstPhysicalPar()->Previous();
2146 } while (newpar && newpar->GetDepth() > deth
2147 && newpar->footnoteflag == footnoteflag);
2150 if (Previous() || GetDepth())
2151 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2155 return newpar->FirstPhysicalPar();
2159 int LyXParagraph::AutoDeleteInsets()
2161 #ifdef NEW_INSETTABLE
2162 vector<size_type> tmpvec;
2164 for (InsetList::iterator it = insetlist.begin();
2165 it != insetlist.end(); ++it) {
2166 if ((*it).inset && (*it).inset->AutoDelete()) {
2167 tmpvec.push_back((*it).pos);
2171 for (vector<size_type>::const_iterator cit = tmpvec.begin();
2172 cit != tmpvec.end(); ++cit) {
2177 InsetTable * tmpi = insettable;
2178 InsetTable * tmpi2 = tmpi;
2184 if (tmpi2->inset->AutoDelete()) {
2189 lyxerr << "ERROR (LyXParagraph::AutoDeleteInsets): "
2190 "cannot auto-delete insets" << endl;
2198 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
2200 #ifdef NEW_INSETTABLE
2201 InsetList::iterator it2 = insetlist.end();
2202 for (InsetList::iterator it = insetlist.begin();
2203 it != insetlist.end(); ++it) {
2204 if ((*it).pos >= pos) {
2205 if (it2 != insetlist.end() || (*it).pos < (*it2).pos)
2209 if (it2 != insetlist.end()) {
2211 return (*it2).inset;
2215 InsetTable * tmpi = insettable;
2216 InsetTable * tmpi2 = 0;
2218 if (tmpi->pos >= pos) {
2219 if (!tmpi2 || tmpi->pos < tmpi2->pos)
2226 return tmpi2->inset;
2234 // returns -1 if inset not found
2235 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2238 #ifdef NEW_INSETTABLE
2239 for (InsetList::const_iterator cit = insetlist.begin();
2240 cit != insetlist.end(); ++cit) {
2241 if ((*cit).inset == inset) {
2246 InsetTable * tmpi = insettable;
2247 while (tmpi && tmpi->inset != inset) {
2250 if (tmpi && tmpi->inset)
2253 // Think about footnotes.
2254 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2255 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2257 NextAfterFootnote()->GetPositionOfInset(inset);
2259 return text.size() + 1 + further;
2265 void LyXParagraph::readSimpleWholeFile(istream & is)
2271 InsertChar(text.size(), c);
2276 LyXParagraph * LyXParagraph::TeXOnePar(string & file, TexRow & texrow,
2277 string & foot, TexRow & foot_texrow,
2280 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2281 LyXParagraph * par = next;
2282 LyXLayout const & style =
2283 textclasslist.Style(current_view->buffer()->params.textclass,
2286 bool further_blank_line = false;
2288 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2290 if (start_of_appendix) {
2291 file += "\\appendix\n";
2295 if (tex_code_break_column && style.isCommand()){
2300 if (pagebreak_top) {
2301 file += "\\newpage";
2302 further_blank_line = true;
2304 if (added_space_top.kind() != VSpace::NONE) {
2305 file += added_space_top.asLatexCommand();
2306 further_blank_line = true;
2310 file += "\\lyxline{\\" + getFont(0).latexSize() + '}';
2311 file += "\\vspace{-1\\parskip}";
2312 further_blank_line = true;
2315 if (further_blank_line){
2320 switch (style.latextype) {
2323 file += style.latexname();
2324 file += style.latexparam();
2326 case LATEX_ITEM_ENVIRONMENT:
2328 bibkey->Latex(file, false);
2332 case LATEX_LIST_ENVIRONMENT:
2339 bool need_par = SimpleTeXOnePar(file, texrow);
2341 // Spit out footnotes
2342 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2343 && par->footnoteflag != footnoteflag) {
2344 par = par->TeXFootnote(file, texrow,
2345 foot, foot_texrow, foot_count);
2346 par->SimpleTeXOnePar(file, texrow);
2350 // Make sure that \\par is done with the font of the last
2351 // character if this has another size as the default.
2352 // This is necessary because LaTeX (and LyX on the screen)
2353 // calculates the space between the baselines according
2354 // to this font. (Matthias)
2355 LyXFont font = getFont(Last()-1);
2357 if (style.resfont.size() != font.size()) {
2359 file += font.latexSize();
2363 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2364 GetLayout()).isCommand()){
2365 if (style.resfont.size() != font.size()) {
2367 file += font.latexSize();
2371 } else if (style.resfont.size() != font.size()){
2372 file += "{\\" + font.latexSize() + " \\par}";
2375 switch (style.latextype) {
2376 case LATEX_ITEM_ENVIRONMENT:
2377 case LATEX_LIST_ENVIRONMENT:
2378 if (par && (depth < par->depth)) {
2383 case LATEX_ENVIRONMENT:
2384 // if its the last paragraph of the current environment
2385 // skip it otherwise fall through
2387 && (par->layout != layout
2388 || par->depth != depth
2389 || par->pextra_type != pextra_type))
2392 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2393 && footnotekind != LyXParagraph::FOOTNOTE
2394 && footnotekind != LyXParagraph::MARGIN
2398 // don't insert this if we would be adding it
2399 // before or after a table in a float. This
2400 // little trick is needed in order to allow
2401 // use of tables in \subfigures or \subtables.
2407 further_blank_line = false;
2409 file += "\\lyxline{\\" + getFont(Last()-1).latexSize() + '}';
2410 further_blank_line = true;
2413 if (added_space_bottom.kind() != VSpace::NONE) {
2414 file += added_space_bottom.asLatexCommand();
2415 further_blank_line = true;
2418 if (pagebreak_bottom) {
2419 file += "\\newpage";
2420 further_blank_line = true;
2423 if (further_blank_line){
2428 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2429 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2434 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2439 // This one spits out the text of the paragraph
2440 bool LyXParagraph::SimpleTeXOnePar(string & file, TexRow & texrow)
2442 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2445 return SimpleTeXOneTablePar(file, texrow);
2448 size_type main_body;
2450 bool return_value = false;
2452 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass, GetLayout());
2455 // Maybe we have to create a optional argument.
2456 if (style.labeltype != LABEL_MANUAL)
2459 main_body = BeginningOfMainBody();
2461 if (main_body > 0) {
2463 basefont = getFont(-2); // Get label font
2465 basefont = getFont(-1); // Get layout font
2473 if (style.isCommand()) {
2476 } else if (align != LYX_ALIGN_LAYOUT) {
2479 return_value = true;
2483 // Which font is currently active?
2484 LyXFont running_font = basefont;
2485 // Do we have an open font change?
2486 bool open_font = false;
2488 texrow.start(this, 0);
2490 for (size_type i = 0; i < size(); ++i) {
2492 // First char in paragraph or after label?
2493 if (i == main_body && !IsDummy()) {
2494 if (main_body > 0) {
2496 column += running_font.latexWriteEndChanges(file, basefont);
2499 basefont = getFont(-1); // Now use the layout font
2500 running_font = basefont;
2504 if (style.isCommand()) {
2507 } else if (align != LYX_ALIGN_LAYOUT) {
2510 return_value = true;
2514 file += "\\noindent ";
2518 case LYX_ALIGN_NONE:
2519 case LYX_ALIGN_BLOCK:
2520 case LYX_ALIGN_LAYOUT:
2521 case LYX_ALIGN_SPECIAL: break;
2522 case LYX_ALIGN_LEFT:
2523 file += "\\raggedright ";
2526 case LYX_ALIGN_RIGHT:
2527 file += "\\raggedleft ";
2530 case LYX_ALIGN_CENTER:
2531 file += "\\centering ";
2539 // Fully instantiated font
2540 LyXFont font = getFont(i);
2542 // Spaces at end of font change are simulated to be
2543 // outside font change, i.e. we write "\textXX{text} "
2544 // rather than "\textXX{text }". (Asger)
2545 if (open_font && c == ' ' && i <= size() - 2
2546 && !getFont(i+1).equalExceptLatex(running_font)
2547 && !getFont(i+1).equalExceptLatex(font)) {
2548 font = getFont(i + 1);
2550 // We end font definition before blanks
2551 if (!font.equalExceptLatex(running_font) && open_font) {
2552 column += running_font.latexWriteEndChanges(file,
2554 running_font = basefont;
2558 // Blanks are printed before start of fontswitch
2560 // Do not print the separation of the optional argument
2561 if (i != main_body - 1) {
2562 SimpleTeXBlanks(file, texrow, i,
2563 column, font, style);
2567 // Do we need to change font?
2568 if (!font.equalExceptLatex(running_font)
2569 && i != main_body-1) {
2570 column += font.latexWriteStartChanges(file, basefont);
2571 running_font = font;
2575 if (c == LyXParagraph::META_NEWLINE) {
2576 // newlines are handled differently here than
2577 // the default in SimpleTeXSpecialChars().
2578 if (!style.newline_allowed
2579 || font.latex() == LyXFont::ON) {
2583 column += running_font.latexWriteEndChanges(file, basefont);
2586 basefont = getFont(-1);
2587 running_font = basefont;
2588 if (font.family() ==
2589 LyXFont::TYPEWRITER_FAMILY) {
2595 texrow.start(this, i + 1);
2598 SimpleTeXSpecialChars(file, texrow,
2599 font, running_font, basefont,
2600 open_font, style, i, column, c);
2604 // If we have an open font definition, we have to close it
2606 running_font.latexWriteEndChanges(file, basefont);
2609 // Needed if there is an optional argument but no contents.
2610 if (main_body > 0 && main_body == size()) {
2612 return_value = false;
2615 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2616 return return_value;
2620 // This one spits out the text of a table paragraph
2621 bool LyXParagraph::SimpleTeXOneTablePar(string & file, TexRow & texrow)
2623 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2625 bool return_value = false;
2627 LyXLayout const & style =
2628 textclasslist.Style(current_view->buffer()->params.textclass,
2632 if (!IsDummy()) { // it is dummy if it is in a float!!!
2633 if (style.isCommand()) {
2636 } else if (align != LYX_ALIGN_LAYOUT) {
2639 return_value = true;
2642 file += "\\noindent ";
2646 case LYX_ALIGN_NONE:
2647 case LYX_ALIGN_BLOCK:
2648 case LYX_ALIGN_LAYOUT:
2649 case LYX_ALIGN_SPECIAL: break;
2650 case LYX_ALIGN_LEFT:
2651 file += "\\raggedright ";
2654 case LYX_ALIGN_RIGHT:
2655 file += "\\raggedleft ";
2658 case LYX_ALIGN_CENTER:
2659 file += "\\centering ";
2665 LyXFont basefont = getFont(-1); // Get layout font
2666 // Which font is currently active?
2667 LyXFont running_font = basefont;
2668 // Do we have an open font change?
2669 bool open_font = false;
2670 int current_cell_number = -1;
2671 int tmp = table->TexEndOfCell(file, current_cell_number);
2672 for (; tmp > 0 ; --tmp)
2675 texrow.start(this, 0);
2677 for (size_type i = 0; i < size(); ++i) {
2678 char c = GetChar(i);
2679 if (table->IsContRow(current_cell_number+1)) {
2680 if (c == LyXParagraph::META_NEWLINE)
2681 current_cell_number++;
2686 // Fully instantiated font
2687 LyXFont font = getFont(i);
2689 // Spaces at end of font change are simulated to be
2690 // outside font change.
2691 // i.e. we write "\textXX{text} " rather than
2692 // "\textXX{text }". (Asger)
2693 if (open_font && c == ' ' && i <= size() - 2
2694 && getFont(i+1) != running_font && getFont(i+1) != font) {
2695 font = getFont(i+1);
2698 // We end font definition before blanks
2699 if (font != running_font && open_font) {
2700 column += running_font.latexWriteEndChanges(file,
2702 running_font = basefont;
2705 // Blanks are printed before start of fontswitch
2707 SimpleTeXBlanks(file, texrow, i, column, font, style);
2709 // Do we need to change font?
2710 if (font != running_font) {
2711 column += font.latexWriteStartChanges(file, basefont);
2712 running_font = font;
2715 // Do we need to turn on LaTeX mode?
2716 if (font.latex() != running_font.latex()) {
2717 if (font.latex() == LyXFont::ON
2718 && style.needprotect) {
2719 file += "\\protect ";
2723 if (c == LyXParagraph::META_NEWLINE) {
2724 // special case for inside a table
2725 // different from default case in
2726 // SimpleTeXSpecialChars()
2728 column += running_font
2729 .latexWriteEndChanges(file, basefont);
2732 basefont = getFont(-1);
2733 running_font = basefont;
2734 current_cell_number++;
2735 if (table->CellHasContRow(current_cell_number) >= 0) {
2736 TeXContTableRows(file, i+1,
2737 current_cell_number,
2740 // if this cell follow only ContRows till end don't
2741 // put the EndOfCell because it is put after the
2743 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2744 current_cell_number--;
2747 int tmp = table->TexEndOfCell(file,
2748 current_cell_number);
2751 } else if (tmp < 0) {
2757 texrow.start(this, i+1);
2759 SimpleTeXSpecialChars(file, texrow,
2760 font, running_font, basefont,
2761 open_font, style, i, column, c);
2765 // If we have an open font definition, we have to close it
2767 running_font.latexWriteEndChanges(file, basefont);
2769 current_cell_number++;
2770 tmp = table->TexEndOfCell(file, current_cell_number);
2771 for (; tmp > 0; --tmp)
2773 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2774 return return_value;
2778 // This one spits out the text off ContRows in tables
2779 bool LyXParagraph::TeXContTableRows(string & file,
2780 LyXParagraph::size_type i,
2781 int current_cell_number,
2782 int & column, TexRow & texrow)
2784 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2790 bool return_value = false;
2791 LyXLayout const & style =
2792 textclasslist.Style(current_view->buffer()->params.textclass,
2794 LyXFont basefont = getFont(-1); // Get layout font
2795 // Which font is currently active?
2796 LyXFont running_font = basefont;
2797 // Do we have an open font change?
2798 bool open_font = false;
2800 size_type lastpos = i;
2801 int cell = table->CellHasContRow(current_cell_number);
2802 ++current_cell_number;
2804 // first find the right position
2806 for (; (i < size()) && (current_cell_number<cell); ++i) {
2808 if (c == LyXParagraph::META_NEWLINE)
2809 current_cell_number++;
2813 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2817 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2822 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2826 // Fully instantiated font
2827 LyXFont font = getFont(i);
2829 // Spaces at end of font change are simulated to
2830 // be outside font change. i.e. we write
2831 // "\textXX{text} " rather than "\textXX{text }".
2833 if (open_font && c == ' ' && i <= size() - 2
2834 && getFont(i + 1) != running_font
2835 && getFont(i + 1) != font) {
2836 font = getFont(i + 1);
2839 // We end font definition before blanks
2840 if (font != running_font && open_font) {
2841 column += running_font.latexWriteEndChanges(file, basefont);
2842 running_font = basefont;
2845 // Blanks are printed before start of fontswitch
2847 SimpleTeXBlanks(file, texrow, i,
2848 column, font, style);
2850 // Do we need to change font?
2851 if (font != running_font) {
2853 font.latexWriteStartChanges(file,
2855 running_font = font;
2858 // Do we need to turn on LaTeX mode?
2859 if (font.latex() != running_font.latex()) {
2860 if (font.latex() == LyXFont::ON
2861 && style.needprotect)
2863 file += "\\protect ";
2867 SimpleTeXSpecialChars(file, texrow, font,
2868 running_font, basefont,
2869 open_font, style, i, column, c);
2871 // If we have an open font definition, we have to close it
2873 running_font.latexWriteEndChanges(file, basefont);
2876 basefont = getFont(-1);
2877 running_font = basefont;
2878 cell = table->CellHasContRow(current_cell_number);
2880 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2881 return return_value;
2885 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2887 bool retval = false;
2889 case LyXParagraph::META_HFILL:
2890 sgml_string.clear();
2892 case LyXParagraph::META_PROTECTED_SEPARATOR:
2895 case LyXParagraph::META_NEWLINE:
2899 sgml_string = "&";
2902 sgml_string = "<";
2905 sgml_string = ">";
2908 sgml_string = "$";
2911 sgml_string = "#";
2914 sgml_string = "%";
2917 sgml_string = "[";
2920 sgml_string = "]";
2923 sgml_string = "{";
2926 sgml_string = "}";
2929 sgml_string = "˜";
2932 sgml_string = """;
2935 sgml_string = "\";
2941 case '\0': // Ignore :-)
2942 sgml_string.clear();
2952 void LyXParagraph::SimpleDocBookOneTablePar(string & file, string & extra,
2953 int & desc_on, int depth)
2956 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2958 LyXFont font1, font2;
2961 size_type main_body;
2962 string emph = "emphasis";
2963 bool emph_flag = false;
2965 LyXLayout const & style =
2966 textclasslist.Style(current_view->buffer()->params.textclass,
2969 if (style.labeltype != LABEL_MANUAL)
2972 main_body = BeginningOfMainBody();
2974 // Gets paragraph main font.
2976 font1 = style.labelfont;
2980 int char_line_count = depth;
2981 addNewlineAndDepth(file, depth);
2982 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2983 file += "<INFORMALTABLE>";
2984 addNewlineAndDepth(file, ++depth);
2986 int current_cell_number = -1;
2987 int tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
2989 // Parsing main loop.
2990 for (size_type i = 0; i < size(); ++i) {
2992 if (table->IsContRow(current_cell_number+1)) {
2993 if (c == LyXParagraph::META_NEWLINE)
2994 ++current_cell_number;
2999 // Fully instantiated font
3002 // Handle <emphasis> tag.
3003 if (font1.emph() != font2.emph() && i) {
3004 if (font2.emph() == LyXFont::ON) {
3005 file += "<emphasis>";
3007 } else if (emph_flag) {
3008 file += "</emphasis>";
3012 if (c == LyXParagraph::META_NEWLINE) {
3013 // We have only to control for emphasis open here!
3015 file += "</emphasis>";
3018 font1 = font2 = getFont(-1);
3019 current_cell_number++;
3020 if (table->CellHasContRow(current_cell_number) >= 0) {
3021 DocBookContTableRows(file, extra, desc_on, i+1,
3022 current_cell_number,
3025 // if this cell follow only ContRows till end don't
3026 // put the EndOfCell because it is put after the
3028 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3029 current_cell_number--;
3032 tmp= table->DocBookEndOfCell(file, current_cell_number,
3037 } else if (c == LyXParagraph::META_INSET) {
3038 inset = GetInset(i);
3040 inset->DocBook(tmp_out);
3042 // This code needs some explanation:
3043 // Two insets are treated specially
3044 // label if it is the first element in a
3045 // command paragraph
3047 // graphics inside tables or figure floats
3049 // title (the equivalente in latex for this
3051 // and title should come first
3054 if(desc_on != 3 || i != 0) {
3055 if(tmp_out[0] == '@') {
3057 extra += frontStrip(tmp_out,
3060 file += frontStrip(tmp_out,
3065 } else if (font2.latex() == LyXFont::ON) {
3066 // "TeX"-Mode on == > SGML-Mode on.
3072 if (linuxDocConvertChar(c, sgml_string)
3073 && !style.free_spacing) {
3074 // in freespacing mode, spaces are
3075 // non-breaking characters
3080 file += "</term><listitem><para>";
3086 file += sgml_string;
3092 // Needed if there is an optional argument but no contents.
3093 if (main_body > 0 && main_body == size()) {
3098 file += "</emphasis>";
3101 ++current_cell_number;
3102 tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
3103 // Resets description flag correctly.
3106 // <term> not closed...
3110 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3111 file += "</INFORMALTABLE>";
3113 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3118 void LyXParagraph::DocBookContTableRows(string & file, string & extra,
3120 LyXParagraph::size_type i,
3121 int current_cell_number, int &column)
3126 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3131 string emph= "emphasis";
3132 bool emph_flag= false;
3133 int char_line_count= 0;
3135 LyXLayout const & style =
3136 textclasslist.Style(current_view->buffer()->params.textclass,
3139 size_type main_body;
3140 if (style.labeltype != LABEL_MANUAL)
3143 main_body = BeginningOfMainBody();
3145 // Gets paragraph main font.
3148 font1 = style.labelfont;
3152 size_type lastpos = i;
3153 int cell = table->CellHasContRow(current_cell_number);
3154 ++current_cell_number;
3156 // first find the right position
3158 for (; i < size() && current_cell_number < cell; ++i) {
3160 if (c == LyXParagraph::META_NEWLINE)
3161 current_cell_number++;
3165 // I don't know how to handle this so I comment it
3166 // for the moment (Jug)
3167 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3168 // file += " \\\\\n";
3171 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3176 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3180 // Fully instantiated font
3183 // Handle <emphasis> tag.
3184 if (font1.emph() != font2.emph() && i) {
3185 if (font2.emph() == LyXFont::ON) {
3186 file += "<emphasis>";
3188 } else if (emph_flag) {
3189 file += "</emphasis>";
3193 if (c == LyXParagraph::META_INSET) {
3194 inset = GetInset(i);
3196 inset->DocBook(tmp_out);
3198 // This code needs some explanation:
3199 // Two insets are treated specially
3200 // label if it is the first element in a
3201 // command paragraph
3203 // graphics inside tables or figure floats
3204 // can't go on title (the equivalente in
3205 // latex for this case is caption and title
3206 // should come first
3209 if(desc_on != 3 || i != 0) {
3210 if(tmp_out[0] == '@') {
3212 extra += frontStrip(tmp_out, '@');
3214 file += frontStrip(tmp_out, '@');
3218 } else if (font2.latex() == LyXFont::ON) {
3219 // "TeX"-Mode on == > SGML-Mode on.
3225 if (linuxDocConvertChar(c, sgml_string)
3226 && !style.free_spacing) {
3227 // in freespacing mode, spaces are
3228 // non-breaking characters
3233 file += "</term><listitem><para>";
3239 file += sgml_string;
3243 // we have only to control for emphasis open here!
3245 file += "</emphasis>";
3248 font1 = font2 = getFont(-1);
3249 cell = table->CellHasContRow(current_cell_number);
3251 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3255 void LyXParagraph::SimpleTeXBlanks(string & file, TexRow & texrow,
3256 LyXParagraph::size_type const i,
3257 int & column, LyXFont const & font,
3258 LyXLayout const & style)
3260 if (column > tex_code_break_column
3262 && GetChar(i - 1) != ' '
3264 // In LaTeX mode, we don't want to
3265 // break lines since some commands
3267 && ! (font.latex() == LyXFont::ON)
3268 // same in FreeSpacing mode
3269 && !style.free_spacing
3270 // In typewriter mode, we want to avoid
3271 // ! . ? : at the end of a line
3272 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3273 && (GetChar(i-1) == '.'
3274 || GetChar(i-1) == '?'
3275 || GetChar(i-1) == ':'
3276 || GetChar(i-1) == '!'))) {
3277 if (tex_code_break_column == 0) {
3278 // in batchmode we need LaTeX to still
3279 // see it as a space not as an extra '\n'
3285 texrow.start(this, i+1);
3287 } else if (font.latex() == LyXFont::OFF) {
3288 if (style.free_spacing) {
3297 void LyXParagraph::SimpleTeXSpecialChars(string & file, TexRow & texrow,
3299 LyXFont & running_font,
3302 LyXLayout const & style,
3303 LyXParagraph::size_type & i,
3304 int & column, char const c)
3306 // Two major modes: LaTeX or plain
3307 // Handle here those cases common to both modes
3308 // and then split to handle the two modes separately.
3310 case LyXParagraph::META_INSET: {
3311 Inset * inset = GetInset(i);
3313 int len = file.length();
3314 int tmp = inset->Latex(file, style.isCommand());
3319 column += file.length() - len;
3328 case LyXParagraph::META_NEWLINE:
3330 column += running_font.latexWriteEndChanges(file,
3334 basefont = getFont(-1);
3335 running_font = basefont;
3338 case LyXParagraph::META_HFILL:
3339 file += "\\hfill{}";
3344 // And now for the special cases within each mode
3345 // Are we in LaTeX mode?
3346 if (font.latex() == LyXFont::ON) {
3347 // at present we only have one option
3348 // but I'll leave it as a switch statement
3349 // so its simpler to extend. (ARRae)
3351 case LyXParagraph::META_PROTECTED_SEPARATOR:
3356 // make sure that we will not print
3357 // error generating chars to the tex
3358 // file. This test would not be needed
3359 // if it were done in the buffer
3367 // Plain mode (i.e. not LaTeX)
3369 case LyXParagraph::META_PROTECTED_SEPARATOR:
3374 file += "\\textbackslash{}";
3378 case '°': case '±': case '²': case '³':
3379 case '×': case '÷': case '¹': case 'ª':
3380 case 'º': case '¬': case 'µ':
3381 if (current_view->buffer()->params.inputenc == "latin1") {
3382 file += "\\ensuremath{";
3391 case '|': case '<': case '>':
3392 // In T1 encoding, these characters exist
3393 if (lyxrc->fontenc == "T1") {
3395 //... but we should avoid ligatures
3396 if ((c == '>' || c == '<')
3398 && GetChar(i+1) == c){
3399 file += "\\textcompwordmark{}";
3404 // Typewriter font also has them
3405 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3409 // Otherwise, we use what LaTeX
3413 file += "\\textless{}";
3417 file += "\\textgreater{}";
3421 file += "\\textbar{}";
3427 case '-': // "--" in Typewriter mode -> "-{}-"
3429 && GetChar(i + 1) == '-'
3430 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3439 file += "\\char`\\\"{}";
3444 if (current_view->buffer()->params.inputenc == "default") {
3445 file += "\\pounds{}";
3453 case '%': case '#': case '{':
3461 file += "\\textasciitilde{}";
3466 file += "\\textasciicircum{}";
3470 case '*': case '[': case ']':
3471 // avoid being mistaken for optional arguments
3479 // Blanks are printed before font switching.
3480 // Sure? I am not! (try nice-latex)
3481 // I am sure it's correct. LyX might be smarter
3482 // in the future, but for now, nothing wrong is
3487 /* idea for labels --- begin*/
3491 && font.family() != LyXFont::TYPEWRITER_FAMILY
3492 && GetChar(i + 1) == 'y'
3493 && GetChar(i + 2) == 'X') {
3501 && font.family() != LyXFont::TYPEWRITER_FAMILY
3502 && GetChar(i + 1) == 'e'
3503 && GetChar(i + 2) == 'X') {
3508 // Check for "LaTeX2e"
3511 && font.family() != LyXFont::TYPEWRITER_FAMILY
3512 && GetChar(i + 1) == 'a'
3513 && GetChar(i + 2) == 'T'
3514 && GetChar(i + 3) == 'e'
3515 && GetChar(i + 4) == 'X'
3516 && GetChar(i + 5) == '2'
3517 && GetChar(i + 6) == 'e') {
3518 file += "\\LaTeXe{}";
3522 // Check for "LaTeX"
3525 && font.family() != LyXFont::TYPEWRITER_FAMILY
3526 && GetChar(i + 1) == 'a'
3527 && GetChar(i + 2) == 'T'
3528 && GetChar(i + 3) == 'e'
3529 && GetChar(i + 4) == 'X') {
3530 file += "\\LaTeX{}";
3533 /* idea for labels --- end*/
3534 } else if (c != '\0') {
3544 bool LyXParagraph::RoffContTableRows(ostream & os,
3545 LyXParagraph::size_type i,
3551 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3556 string fname2 = TmpFileName(string(), "RAT2");
3558 int cell = table->CellHasContRow(actcell);
3561 // first find the right position
3563 for (; i < size() && actcell < cell; ++i) {
3565 if (c == LyXParagraph::META_NEWLINE)
3570 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3573 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3575 font2 = GetFontSettings(i);
3576 if (font1.latex() != font2.latex()) {
3577 if (font2.latex() != LyXFont::OFF)
3582 case LyXParagraph::META_INSET:
3583 if ((inset = GetInset(i))) {
3584 fstream fs(fname2.c_str(),
3587 WriteAlert(_("LYX_ERROR:"),
3588 _("Cannot open temporary file:"),
3592 inset->Latex(fs, -1);
3605 case LyXParagraph::META_NEWLINE:
3607 case LyXParagraph::META_HFILL:
3609 case LyXParagraph::META_PROTECTED_SEPARATOR:
3618 lyxerr.debug() << "RoffAsciiTable: "
3619 "NULL char in structure."
3624 cell = table->CellHasContRow(actcell);
3630 LyXParagraph * LyXParagraph::TeXDeeper(string & file, TexRow & texrow,
3631 string & foot, TexRow & foot_texrow,
3634 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3635 LyXParagraph * par = this;
3637 while (par && par->depth == depth) {
3639 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3640 if (textclasslist.Style(current_view->buffer()->params.textclass,
3641 par->layout).isEnvironment()
3642 || par->pextra_type != PEXTRA_NONE)
3644 par = par->TeXEnvironment(file, texrow,
3648 par = par->TeXOnePar(file, texrow,
3653 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3659 LyXParagraph * LyXParagraph::TeXEnvironment(string & file, TexRow & texrow,
3661 TexRow & foot_texrow,
3664 bool eindent_open = false;
3665 bool foot_this_level = false;
3666 // flags when footnotetext should be appended to file.
3667 static bool minipage_open = false;
3668 static int minipage_open_depth = 0;
3669 char par_sep = current_view->buffer()->params.paragraph_separation;
3671 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3673 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3675 LyXLayout const & style =
3676 textclasslist.Style(current_view->buffer()->params.textclass,
3679 if (pextra_type == PEXTRA_INDENT) {
3680 if (!pextra_width.empty()) {
3681 file += "\\begin{LyXParagraphIndent}{"
3682 + pextra_width + "}\n";
3684 //float ib = atof(pextra_widthp.c_str())/100;
3685 // string can't handle floats at present (971109)
3686 // so I'll do a conversion by hand knowing that
3687 // the limits are 0.0 to 1.0. ARRae.
3688 file += "\\begin{LyXParagraphIndent}{";
3689 switch (pextra_widthp.length()) {
3695 file += pextra_widthp;
3699 file += pextra_widthp;
3701 file += "\\columnwidth}\n";
3704 eindent_open = true;
3706 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3707 if (pextra_hfill && Previous() &&
3708 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3709 file += "\\hfill{}\n";
3712 if (par_sep == BufferParams::PARSEP_INDENT) {
3713 file += "{\\setlength\\parindent{0pt}\n";
3716 file += "\\begin{minipage}";
3717 switch(pextra_alignment) {
3718 case MINIPAGE_ALIGN_TOP:
3721 case MINIPAGE_ALIGN_MIDDLE:
3724 case MINIPAGE_ALIGN_BOTTOM:
3728 if (!pextra_width.empty()) {
3730 file += pextra_width + "}\n";
3732 //float ib = atof(par->pextra_width.c_str())/100;
3733 // string can't handle floats at present
3734 // so I'll do a conversion by hand knowing that
3735 // the limits are 0.0 to 1.0. ARRae.
3737 switch (pextra_widthp.length()) {
3743 file += pextra_widthp;
3747 file += pextra_widthp;
3749 file += "\\columnwidth}\n";
3752 if (par_sep == BufferParams::PARSEP_INDENT) {
3753 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3756 minipage_open = true;
3757 minipage_open_depth = depth;
3760 #ifdef WITH_WARNINGS
3761 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3762 //I disabled it because it breaks when lists span on several
3765 if (style.isEnvironment()){
3766 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3767 #ifdef FANCY_FOOTNOTE_CODE
3768 if (foot_count < 0) {
3769 // flag that footnote[mark][text] should be
3770 // used for any footnotes from now on
3772 foot_this_level = true;
3775 file += "\\begin{" + style.latexname() + "}{"
3776 + labelwidthstring + "}\n";
3777 } else if (style.labeltype == LABEL_BIBLIO) {
3779 file += "\\begin{" + style.latexname() + "}{"
3780 + bibitemWidthest() + "}\n";
3781 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3782 #ifdef FANCY_FOOTNOTE_CODE
3783 if (foot_count < 0) {
3784 // flag that footnote[mark][text] should be
3785 // used for any footnotes from now on
3787 foot_this_level = true;
3790 file += "\\begin{" + style.latexname() + '}'
3791 + style.latexparam() + '\n';
3793 file += "\\begin{" + style.latexname() + '}'
3794 + style.latexparam() + '\n';
3797 LyXParagraph * par = this;
3799 par = par->TeXOnePar(file, texrow,
3800 foot, foot_texrow, foot_count);
3802 if (minipage_open && par && !style.isEnvironment() &&
3803 (par->pextra_type == PEXTRA_MINIPAGE) &&
3804 par->pextra_start_minipage) {
3805 file += "\\end{minipage}\n";
3807 if (par_sep == BufferParams::PARSEP_INDENT) {
3811 minipage_open = false;
3813 if (par && par->depth > depth) {
3814 if (textclasslist.Style(current_view->buffer()->params.textclass,
3815 par->layout).isParagraph()
3817 && !suffixIs(file, "\n\n")) {
3818 // There should be at least one '\n' already
3819 // but we need there to be two for Standard
3820 // paragraphs that are depth-increment'ed to be
3821 // output correctly. However, tables can
3822 // also be paragraphs so don't adjust them.
3827 par = par->TeXDeeper(file, texrow,
3828 foot, foot_texrow, foot_count);
3830 if (par && par->layout == layout && par->depth == depth &&
3831 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3832 if (par->pextra_hfill && par->Previous() &&
3833 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3834 file += "\\hfill{}\n";
3837 if (par_sep == BufferParams::PARSEP_INDENT) {
3838 file += "{\\setlength\\parindent{0pt}\n";
3841 file += "\\begin{minipage}";
3842 switch(par->pextra_alignment) {
3843 case MINIPAGE_ALIGN_TOP:
3846 case MINIPAGE_ALIGN_MIDDLE:
3849 case MINIPAGE_ALIGN_BOTTOM:
3853 if (!par->pextra_width.empty()) {
3855 file += par->pextra_width;
3858 //float ib = atof(par->pextra_widthp.c_str())/100;
3859 // string can't handle floats at present
3860 // so I'll do a conversion by hand knowing that
3861 // the limits are 0.0 to 1.0. ARRae.
3863 switch (par->pextra_widthp.length()) {
3869 file += par->pextra_widthp;
3873 file += par->pextra_widthp;
3875 file += "\\columnwidth}\n";
3878 if (par_sep == BufferParams::PARSEP_INDENT) {
3879 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3882 minipage_open = true;
3883 minipage_open_depth = par->depth;
3886 && par->layout == layout
3887 && par->depth == depth
3888 && par->pextra_type == pextra_type);
3890 if (style.isEnvironment()) {
3891 file += "\\end{" + style.latexname() + '}';
3892 // maybe this should go after the minipage closes?
3893 if (foot_this_level) {
3894 if (foot_count >= 1) {
3895 if (foot_count > 1) {
3896 file += "\\addtocounter{footnote}{-";
3897 file += tostr(foot_count - 1);
3901 texrow += foot_texrow;
3903 foot_texrow.reset();
3908 if (minipage_open && (minipage_open_depth == depth) &&
3909 (!par || par->pextra_start_minipage ||
3910 par->pextra_type != PEXTRA_MINIPAGE)) {
3911 file += "\\end{minipage}\n";
3913 if (par_sep == BufferParams::PARSEP_INDENT) {
3917 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3918 file += "\\medskip\n\n";
3922 minipage_open = false;
3925 file += "\\end{LyXParagraphIndent}\n";
3928 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3929 && par->pextra_hfill)) {
3933 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3934 return par; // ale970302
3938 LyXParagraph * LyXParagraph::TeXFootnote(string & file, TexRow & texrow,
3939 string & foot, TexRow & foot_texrow,
3942 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3943 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3944 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3945 "No footnote!" << endl;
3947 LyXParagraph * par = this;
3948 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass,
3949 previous->GetLayout());
3951 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3952 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3953 "Float other than footnote in command"
3954 " with moving argument is illegal" << endl;
3957 if (footnotekind != LyXParagraph::FOOTNOTE
3958 && footnotekind != LyXParagraph::MARGIN
3960 && !suffixIs(file, '\n')) {
3961 // we need to ensure that real floats like tables and figures
3962 // have their \begin{} on a new line otherwise we can get
3963 // incorrect results when using the endfloat.sty package
3964 // especially if two floats follow one another. ARRae 981022
3965 // NOTE: if the file is length 0 it must have just been
3966 // written out so we assume it ended with a '\n'
3971 BufferParams * params = ¤t_view->buffer()->params;
3972 bool footer_in_body = true;
3973 switch (footnotekind) {
3974 case LyXParagraph::FOOTNOTE:
3975 if (style.intitle) {
3976 file += "\\thanks{\n";
3977 footer_in_body = false;
3979 if (foot_count == -1) {
3980 // we're at depth 0 so we can use:
3981 file += "\\footnote{%\n";
3982 footer_in_body = false;
3984 file += "\\footnotemark{}%\n";
3986 // we only need this when there are
3987 // multiple footnotes
3988 foot += "\\stepcounter{footnote}";
3990 foot += "\\footnotetext{%\n";
3991 foot_texrow.start(this, 0);
3992 foot_texrow.newline();
3997 case LyXParagraph::MARGIN:
3998 file += "\\marginpar{\n";
4000 case LyXParagraph::FIG:
4001 if (pextra_type == PEXTRA_FLOATFLT
4002 && (!pextra_width.empty()
4003 || !pextra_widthp.empty())) {
4005 if (!pextra_width.empty())
4006 sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
4007 pextra_width.c_str());
4010 "\\begin{floatingfigure}{%f\\textwidth}\n",
4011 atoi(pextra_widthp.c_str())/100.0);
4014 file += "\\begin{figure}";
4015 if (!params->float_placement.empty()) {
4017 file += params->float_placement;
4024 case LyXParagraph::TAB:
4025 file += "\\begin{table}";
4026 if (!params->float_placement.empty()) {
4028 file += params->float_placement;
4034 case LyXParagraph::WIDE_FIG:
4035 file += "\\begin{figure*}";
4036 if (!params->float_placement.empty()) {
4038 file += params->float_placement;
4044 case LyXParagraph::WIDE_TAB:
4045 file += "\\begin{table*}";
4046 if (!params->float_placement.empty()) {
4048 file += params->float_placement;
4054 case LyXParagraph::ALGORITHM:
4055 file += "\\begin{algorithm}\n";
4060 if (footnotekind != LyXParagraph::FOOTNOTE
4061 || !footer_in_body) {
4062 // Process text for all floats except footnotes in body
4064 LyXLayout const & style =
4065 textclasslist.Style(current_view->buffer()->params.textclass,
4068 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4070 if (style.isEnvironment()
4071 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4072 // Allows the use of minipages within float
4073 // environments. Shouldn't be circular because
4074 // we don't support footnotes inside
4075 // floats (yet). ARRae
4076 par = par->TeXEnvironment(file, texrow,
4080 par = par->TeXOnePar(file, texrow,
4085 if (par && !par->IsDummy() && par->depth > depth) {
4086 par = par->TeXDeeper(file, texrow,
4090 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4092 // process footnotes > depth 0 or in environments separately
4093 // NOTE: Currently don't support footnotes within footnotes
4094 // even though that is possible using the \footnotemark
4096 TexRow dummy_texrow;
4097 int dummy_count = 0;
4099 LyXLayout const & style =
4100 textclasslist.Style(current_view->buffer()->params.textclass,
4103 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4105 if (style.isEnvironment()
4106 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4107 // Allows the use of minipages within float
4108 // environments. Shouldn't be circular because
4109 // we don't support footnotes inside
4110 // floats (yet). ARRae
4111 par = par->TeXEnvironment(foot, foot_texrow,
4112 dummy, dummy_texrow,
4115 par = par->TeXOnePar(foot, foot_texrow,
4116 dummy, dummy_texrow,
4120 if (par && !par->IsDummy() && par->depth > depth) {
4121 par = par->TeXDeeper(foot, foot_texrow,
4122 dummy, dummy_texrow,
4126 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4128 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4129 "Footnote in a Footnote -- not supported"
4134 switch (footnotekind) {
4135 case LyXParagraph::FOOTNOTE:
4136 if (footer_in_body) {
4137 // This helps tell which of the multiple
4138 // footnotetexts an error was in.
4140 foot_texrow.newline();
4145 case LyXParagraph::MARGIN:
4148 case LyXParagraph::FIG:
4149 if (pextra_type == PEXTRA_FLOATFLT
4150 && (!pextra_width.empty()
4151 || !pextra_widthp.empty()))
4152 file += "\\end{floatingfigure}";
4154 file += "\\end{figure}";
4156 case LyXParagraph::TAB:
4157 file += "\\end{table}";
4159 case LyXParagraph::WIDE_FIG:
4160 file += "\\end{figure*}";
4162 case LyXParagraph::WIDE_TAB:
4163 file += "\\end{table*}";
4165 case LyXParagraph::ALGORITHM:
4166 file += "\\end{algorithm}";
4170 if (footnotekind != LyXParagraph::FOOTNOTE
4171 && footnotekind != LyXParagraph::MARGIN) {
4172 // we need to ensure that real floats like tables and figures
4173 // have their \end{} on a line of their own otherwise we can
4174 // get incorrect results when using the endfloat.sty package.
4179 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4184 void LyXParagraph::SetPExtraType(int type, char const * width,
4185 char const * widthp)
4188 pextra_width = width;
4189 pextra_widthp = widthp;
4191 if (textclasslist.Style(current_view->buffer()->params.textclass,
4192 layout).isEnvironment()) {
4197 while (par && (par->layout == layout)
4198 && (par->depth == depth)) {
4200 par = par->Previous();
4202 par = par->FirstPhysicalPar();
4203 while (par && par->depth > depth) {
4204 par = par->Previous();
4206 par = par->FirstPhysicalPar();
4210 while (par && (par->layout == layout)
4211 && (par->depth == depth)) {
4212 par->pextra_type = type;
4213 par->pextra_width = width;
4214 par->pextra_widthp = widthp;
4215 par = par->NextAfterFootnote();
4216 if (par && (par->depth > depth))
4217 par->SetPExtraType(type, width, widthp);
4218 while (par && ((par->depth > depth) || par->IsDummy()))
4219 par = par->NextAfterFootnote();
4225 void LyXParagraph::UnsetPExtraType()
4227 if (pextra_type == PEXTRA_NONE)
4230 pextra_type = PEXTRA_NONE;
4231 pextra_width.clear();
4232 pextra_widthp.clear();
4234 if (textclasslist.Style(current_view->buffer()->params.textclass,
4235 layout).isEnvironment()) {
4240 while (par && (par->layout == layout)
4241 && (par->depth == depth)) {
4243 par = par->Previous();
4245 par = par->FirstPhysicalPar();
4246 while (par && par->depth > depth) {
4247 par = par->Previous();
4249 par = par->FirstPhysicalPar();
4253 while (par && (par->layout == layout)
4254 && (par->depth == depth)) {
4255 par->pextra_type = PEXTRA_NONE;
4256 par->pextra_width.clear();
4257 par->pextra_widthp.clear();
4258 par = par->NextAfterFootnote();
4259 if (par && (par->depth > depth))
4260 par->UnsetPExtraType();
4261 while (par && ((par->depth > depth) || par->IsDummy()))
4262 par = par->NextAfterFootnote();
4268 bool LyXParagraph::IsHfill(size_type pos) const
4270 return IsHfillChar(GetChar(pos));
4274 bool LyXParagraph::IsInset(size_type pos) const
4276 return IsInsetChar(GetChar(pos));
4280 bool LyXParagraph::IsFloat(size_type pos) const
4282 return IsFloatChar(GetChar(pos));
4286 bool LyXParagraph::IsNewline(size_type pos) const
4290 tmp = IsNewlineChar(GetChar(pos));
4295 bool LyXParagraph::IsSeparator(size_type pos) const
4297 return IsSeparatorChar(GetChar(pos));
4301 bool LyXParagraph::IsLineSeparator(size_type pos) const
4303 return IsLineSeparatorChar(GetChar(pos));
4307 bool LyXParagraph::IsKomma(size_type pos) const
4309 return IsKommaChar(GetChar(pos));
4313 /// Used by the spellchecker
4314 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4316 unsigned char c = GetChar(pos);
4317 if (IsLetterChar(c))
4319 // '\0' is not a letter, allthough every string contains "" (below)
4322 // We want to pass the ' and escape chars to ispell
4323 string extra = lyxrc->isp_esc_chars + '\'';
4327 return contains(extra, ch);
4331 bool LyXParagraph::IsWord(size_type pos ) const
4333 return IsWordChar(GetChar(pos)) ;