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;
76 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
78 align = LYX_ALIGN_BLOCK;
80 /* table stuff -- begin*/
82 /* table stuff -- end*/
84 bibkey = 0; // ale970302
89 // This konstruktor inserts the new paragraph in a list.
90 LyXParagraph::LyXParagraph(LyXParagraph * par)
93 par->text.resize(par->text.size());
95 for (int i = 0; i < 10; ++i) setCounter(i, 0);
99 // double linked list begin
102 next->previous = this;
104 previous->next = this;
106 #ifndef NEW_FONTTABLE // OK
109 #ifndef NEW_INSETTABLE
112 footnoteflag = LyXParagraph::NO_FOOTNOTE;
113 footnotekind = LyXParagraph::FOOTNOTE;
115 /* table stuff -- begin*/
117 /* table stuff -- end*/
118 id_ = paragraph_id++;
120 bibkey = 0; // ale970302
126 void LyXParagraph::writeFile(ostream & os, BufferParams & params,
127 char footflag, char dth)
129 LyXFont font1, font2;
135 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
137 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
139 // The beginning or the end of a footnote environment?
140 if (footflag != footnoteflag) {
141 footflag = footnoteflag;
143 os << "\n\\begin_float "
144 << 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 ";
159 while (depth < dth) {
160 os << "\n\\end_deeper ";
166 // First write the layout
168 << textclasslist.NameOfLayout(params.textclass, layout)
171 // Maybe some vertical spaces.
172 if (added_space_top.kind() != VSpace::NONE)
173 os << "\\added_space_top "
174 << added_space_top.asLyXCommand() << " ";
175 if (added_space_bottom.kind() != VSpace::NONE)
176 os << "\\added_space_bottom "
177 << added_space_bottom.asLyXCommand() << " ";
179 // The labelwidth string used in lists.
180 if (!labelwidthstring.empty())
181 os << "\\labelwidthstring "
182 << labelwidthstring << '\n';
184 // Lines above or below?
188 os << "\\line_bottom ";
190 // Pagebreaks above or below?
192 os << "\\pagebreak_top ";
193 if (pagebreak_bottom)
194 os << "\\pagebreak_bottom ";
196 // Start of appendix?
197 if (start_of_appendix)
198 os << "\\start_of_appendix ";
205 if (align != LYX_ALIGN_LAYOUT) {
207 case LYX_ALIGN_LEFT: h = 1; break;
208 case LYX_ALIGN_RIGHT: h = 2; break;
209 case LYX_ALIGN_CENTER: h = 3; break;
210 default: h = 0; break;
212 os << "\\align " << string_align[h] << " ";
214 if (pextra_type != PEXTRA_NONE) {
215 os << "\\pextra_type " << pextra_type;
216 if (pextra_type == PEXTRA_MINIPAGE) {
217 os << " \\pextra_alignment "
220 os << " \\pextra_hfill "
222 if (pextra_start_minipage)
223 os << " \\pextra_start_minipage "
224 << pextra_start_minipage;
226 if (!pextra_width.empty()) {
227 os << " \\pextra_width "
228 << VSpace(pextra_width).asLyXCommand();
229 } else if (!pextra_widthp.empty()) {
230 os << " \\pextra_widthp "
236 // Dummy layout. This means that a footnote ended.
237 os << "\n\\end_float ";
238 footflag = LyXParagraph::NO_FOOTNOTE;
241 // It might be a table.
243 os << "\\LyXTable\n";
251 font1 = LyXFont(LyXFont::ALL_INHERIT);
254 for (size_type i = 0; i < size(); ++i) {
260 // Write font changes
261 font2 = GetFontSettings(i);
262 if (font2 != font1) {
263 font2.lyxWriteChanges(font1, os);
273 if (inset->DirectWrite()) {
274 // international char, let it write
275 // code directly so it's shorter in
279 os << "\n\\begin_inset ";
281 os << "\n\\end_inset \n\n";
286 os << "\n\\newline \n";
290 os << "\n\\hfill \n";
293 case META_PROTECTED_SEPARATOR:
294 os << "\n\\protected_separator \n";
298 os << "\n\\backslash \n";
302 if (i + 1 < size() && GetChar(i + 1) == ' ') {
309 if ((column > 70 && c == ' ')
314 // this check is to amend a bug. LyX sometimes
315 // inserts '\0' this could cause problems.
319 lyxerr << "ERROR (LyXParagraph::writeFile):"
320 " NULL char in structure." << endl;
326 // now write the next paragraph
328 next->writeFile(os, params, footflag, dth);
332 void LyXParagraph::validate(LaTeXFeatures & features)
334 // this will be useful later
335 LyXLayout const & layout =
336 textclasslist.Style(current_view->buffer()->params.textclass,
340 if (line_top || line_bottom)
341 features.lyxline = true;
344 features.layout[GetLayout()] = true;
347 #ifdef NEW_FONTTABLE // OK, but does not affect structure anyway
348 for (FontList::const_iterator cit = fontlist.begin();
349 cit != fontlist.end(); ++cit) {
350 if ((*cit).font.noun() == LyXFont::ON) {
351 lyxerr[Debug::LATEX] << "font.noun: "
352 << (*cit).font.noun()
354 features.noun = true;
355 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
356 << (*cit).font.stateText()
359 switch ((*cit).font.color()) {
361 case LyXFont::INHERIT_COLOR:
362 case LyXFont::IGNORE_COLOR:
365 features.color = true;
366 lyxerr[Debug::LATEX] << "Color enabled. Font: "
367 << (*cit).font.stateText()
372 FontTable * tmpfonttable = fonttable;
373 while (tmpfonttable) {
374 if (tmpfonttable->font.noun() == LyXFont::ON) {
375 lyxerr[Debug::LATEX] << "font.noun: "
376 << tmpfonttable->font.noun()
378 features.noun = true;
379 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
380 << tmpfonttable->font.stateText()
383 switch (tmpfonttable->font.color()) {
385 case LyXFont::INHERIT_COLOR:
386 case LyXFont::IGNORE_COLOR:
389 features.color = true;
390 lyxerr[Debug::LATEX] << "Color enabled. Font: "
391 << tmpfonttable->font.stateText()
394 tmpfonttable = tmpfonttable->next;
398 #ifdef NEW_INSETTABLE
399 for (InsetList::const_iterator cit = insetlist.begin();
400 cit != insetlist.end(); ++cit) {
402 (*cit).inset->Validate(features);
405 InsetTable * tmpinsettable = insettable;
406 while (tmpinsettable) {
407 if (tmpinsettable->inset) {
408 tmpinsettable->inset->Validate(features);
410 tmpinsettable = tmpinsettable->next;
414 if (table && table->IsLongTable())
415 features.longtable = true;
416 if (pextra_type == PEXTRA_INDENT)
417 features.LyXParagraphIndent = true;
418 if (pextra_type == PEXTRA_FLOATFLT)
419 features.floatflt = true;
420 if (layout.needprotect
421 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
422 features.NeedLyXFootnoteCode = true;
423 if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
424 (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
425 features.NeedLyXMinipageIndent = true;
426 if (table && table->NeedRotating())
427 features.rotating = true;
428 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
429 features.algorithm = true;
433 // First few functions needed for cut and paste and paragraph breaking.
434 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
436 minibuffer_char = GetChar(pos);
437 minibuffer_font = GetFontSettings(pos);
438 minibuffer_inset = 0;
439 if (minibuffer_char == LyXParagraph::META_INSET) {
441 minibuffer_inset = GetInset(pos)->Clone();
443 minibuffer_inset = 0;
444 minibuffer_char = ' ';
445 // This reflects what GetInset() does (ARRae)
451 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
453 minibuffer_char = GetChar(pos);
454 minibuffer_font = GetFontSettings(pos);
455 minibuffer_inset = 0;
456 if (minibuffer_char == LyXParagraph::META_INSET) {
458 minibuffer_inset = GetInset(pos);
459 // This is a little hack since I want exactly
460 // the inset, not just a clone. Otherwise
461 // the inset would be deleted when calling Erase(pos)
463 #ifdef NEW_INSETTABLE
464 for (InsetList::iterator it = insetlist.begin();
465 it != insetlist.end(); ++it) {
466 if ((*it).pos == pos) {
473 InsetTable * tmpi = insettable;
474 while (tmpi && tmpi->pos != pos) {
477 if (tmpi) { // This should always be true.
482 minibuffer_inset = 0;
483 minibuffer_char = ' ';
484 // This reflects what GetInset() does (ARRae)
489 // Erase(pos); now the caller is responsible for that.
493 void LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
495 InsertChar(pos, minibuffer_char);
496 SetFont(pos, minibuffer_font);
497 if (minibuffer_char == LyXParagraph::META_INSET)
498 InsertInset(pos, minibuffer_inset);
505 void LyXParagraph::Clear()
510 pagebreak_top = false;
511 pagebreak_bottom = false;
513 added_space_top = VSpace(VSpace::NONE);
514 added_space_bottom = VSpace(VSpace::NONE);
516 align = LYX_ALIGN_LAYOUT;
520 pextra_type = PEXTRA_NONE;
521 pextra_width.clear();
522 pextra_widthp.clear();
523 pextra_alignment = MINIPAGE_ALIGN_TOP;
524 pextra_hfill = false;
525 pextra_start_minipage = false;
528 labelwidthstring.clear();
532 start_of_appendix = false;
536 // the destructor removes the new paragraph from the list
537 LyXParagraph::~LyXParagraph()
540 previous->next = next;
542 next->previous = previous;
544 #ifdef NEW_INSETTABLE
545 for (InsetList::iterator it = insetlist.begin();
546 it != insetlist.end(); ++it) {
550 InsetTable * tmpinset;
552 tmpinset = insettable;
553 insettable = insettable->next;
554 if (tmpinset->inset) // DEL LINE
555 delete tmpinset->inset;
557 if (insettable && insettable->next == insettable) {
558 // somehow this recursion appears occasionally
559 // but I can't find where. This bandaid
560 // helps but isn't the best fix. (ARRae)
561 if (insettable->inset) { // DEL LINE
562 delete insettable->inset;
569 #ifndef NEW_FONTTABLE // OK
573 fonttable = fonttable->next;
578 /* table stuff -- begin*/
579 if (table) // DEL LINE
581 /* table stuff -- end*/
584 if (bibkey) // DEL LINE
589 void LyXParagraph::Erase(LyXParagraph::size_type pos)
591 // > because last is the next unused position, and you can
592 // use it if you want
594 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
595 NextAfterFootnote()->Erase(pos - text.size() - 1);
597 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
598 "position does not exist." << endl;
601 if (pos < size()) { // last is free for insertation, but should be empty
602 // if it is an inset, delete the inset entry
603 if (text[pos] == LyXParagraph::META_INSET) {
605 #ifdef NEW_INSETTABLE
606 for (InsetList::iterator it = insetlist.begin();
607 it != insetlist.end(); ++it) {
608 if ((*it).pos == pos) {
615 InsetTable *tmpi = insettable;
616 InsetTable *tmpi2 = tmpi;
617 while (tmpi && tmpi->pos != pos) {
621 if (tmpi) { // this should always be true
622 if (tmpi->inset) // delete the inset if it exists // DEL LINE
624 if (tmpi == insettable)
625 insettable = tmpi->next;
627 tmpi2->next = tmpi->next;
632 text.erase(text.begin() + pos);
633 // Erase entries in the tables.
634 #ifdef NEW_FONTTABLE // Seems OK
635 for (FontList::iterator it = fontlist.begin();
636 it != fontlist.end(); ++it) {
637 if (pos >= (*it).pos && pos <= (*it).pos_end) {
638 if ((*it).pos == (*it).pos_end) {
639 // If it is a multi-character font
640 // entry, we just make it smaller
641 // (see update below), otherwise we
648 // Update all other entries.
649 for (FontList::iterator it = fontlist.begin();
650 it != fontlist.end(); ++it) {
653 if ((*it).pos_end >= pos)
658 FontTable * tmp = fonttable;
659 FontTable * prev = 0;
660 while (tmp && !found) {
661 if (pos >= tmp->pos && pos <= tmp->pos_end)
669 if (found && tmp->pos == tmp->pos_end) {
670 // if it is a multi-character font entry, we just make
671 // it smaller (see update below), otherwise we should
674 prev->next = tmp->next;
676 fonttable = tmp->next;
681 // Update all other entries.
687 if (tmp->pos_end >= pos)
692 // Update the inset table.
693 #ifdef NEW_INSETTABLE
694 for (InsetList::iterator it = insetlist.begin();
695 it != insetlist.end(); ++it) {
700 InsetTable * tmpi = insettable;
708 lyxerr << "ERROR (LyXParagraph::Erase): "
709 "can't erase non-existant char." << endl;
714 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
716 // > because last is the next unused position, and you can
717 // use it if you want
720 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
721 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
724 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
725 "position does not exist." << endl;
728 text.insert(text.begin() + pos, c);
729 // Update the font table.
730 #ifdef NEW_FONTTABLE // Seems OK
731 for (FontList::iterator it = fontlist.begin();
732 it != fontlist.end(); ++it) {
733 if ((*it).pos >= pos)
735 if ((*it).pos_end >= pos)
739 FontTable * tmp = fonttable;
743 if (tmp->pos_end >= pos)
749 // Update the inset table.
750 #ifdef NEW_INSETTABLE
751 for (InsetList::iterator it = insetlist.begin();
752 it != insetlist.end(); ++it) {
753 if ((*it).pos >= pos)
757 InsetTable * tmpi = insettable;
759 if (tmpi->pos >= pos)
767 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
770 // > because last is the next unused position, and you can
771 // use it if you want
774 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
776 ->InsertInset(pos - text.size() - 1, inset);
778 lyxerr << "ERROR (LyXParagraph::InsertInset): "
779 "position does not exist: " << pos << endl;
782 if (text[pos] != LyXParagraph::META_INSET) {
783 lyxerr << "ERROR (LyXParagraph::InsertInset): "
784 "there is no LyXParagraph::META_INSET" << endl;
789 // Add a new entry in the inset table.
790 #ifdef NEW_INSETTABLE
792 InsetList::iterator it =
793 insetlist.insert(insetlist.begin(), tmpi);
797 InsetTable * tmpi = new InsetTable;
800 tmpi->next = insettable;
807 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
811 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
812 return NextAfterFootnote()
813 ->GetInset(pos - text.size() - 1);
815 lyxerr << "ERROR (LyXParagraph::GetInset): "
816 "position does not exist: "
822 #ifdef NEW_INSETTABLE
823 for (InsetList::iterator it = insetlist.begin();
824 it != insetlist.end(); ++it) {
825 if ((*it).pos == pos) {
829 lyxerr << "ERROR (LyXParagraph::GetInset): "
830 "Inset does not exist: " << pos << endl;
831 text[pos] = ' '; // WHY!!! does this set the pos to ' '????
832 // Did this commenting out introduce a bug? So far I have not
833 // see any, please enlighten me. (Lgb)
834 // My guess is that since the inset does not exist, we might
835 // as well replace it with a space to prevent craches. (Asger)
838 InsetTable * tmpi = insettable;
840 while (tmpi && tmpi->pos != pos)
846 lyxerr << "ERROR (LyXParagraph::GetInset): "
847 "Inset does not exist: " << pos << endl;
848 text[pos] = ' '; /// WHY!!! does this set the pos to ' '????
849 // Did this commenting out introduce a bug? So far I have not
850 // seen any, please enlighten me. (Lgb)
851 // My guess is that since the inset does not exist, we might
852 // as well replace it with a space to prevent crashes. (Asger)
859 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
863 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
864 return NextAfterFootnote()
865 ->GetInset(pos - text.size() - 1);
867 lyxerr << "ERROR (LyXParagraph::GetInset): "
868 "position does not exist: "
874 #ifdef NEW_INSETTABLE
875 for (InsetList::const_iterator cit = insetlist.begin();
876 cit != insetlist.end(); ++cit) {
877 if ((*cit).pos == pos) {
881 lyxerr << "ERROR (LyXParagraph::GetInset): "
882 "Inset does not exist: " << pos << endl;
883 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
884 // Did this commenting out introduce a bug? So far I have not
885 // see any, please enlighten me. (Lgb)
886 // My guess is that since the inset does not exist, we might
887 // as well replace it with a space to prevent craches. (Asger)
890 InsetTable * tmpi = insettable;
892 while (tmpi && tmpi->pos != pos)
898 lyxerr << "ERROR (LyXParagraph::GetInset): "
899 "Inset does not exist: " << pos << endl;
900 // in the const version we need to comment it out anyway...
901 //text[pos] = ' '; /// WHY!!! does this set the pos to ' '????
902 // Did this commenting out introduce a bug? So far I have not
903 // seen any, please enlighten me. (Lgb)
904 // My guess is that since the inset does not exist, we might
905 // as well replace it with a space to prevent crashes. (Asger)
912 // Gets uninstantiated font setting at position.
913 // Optimized after profiling. (Asger)
914 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
917 #ifdef NEW_FONTTABLE // Seems OK
918 for (FontList::const_iterator cit = fontlist.begin();
919 cit != fontlist.end(); ++cit) {
920 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
924 FontTable * tmp = fonttable;
926 if (pos >= tmp->pos && pos <= tmp->pos_end)
932 // > because last is the next unused position, and you can
933 // use it if you want
934 else if (pos > size()) {
936 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
937 return NextAfterFootnote()
938 ->GetFontSettings(pos - text.size() - 1);
940 // Why is it an error to ask for the font of a
941 // position that does not exist? Would it be
942 // enough for this to be enabled on debug?
943 // We want strict error checking, but it's ok to only
944 // have it when debugging. (Asger)
945 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
946 "position does not exist. "
947 << pos << " (" << static_cast<int>(pos)
951 return GetFontSettings(pos - 1);
953 return LyXFont(LyXFont::ALL_INHERIT);
957 // Gets the fully instantiated font at a given position in a paragraph
958 // This is basically the same function as LyXText::GetFont() in text2.C.
959 // The difference is that this one is used for generating the LaTeX file,
960 // and thus cosmetic "improvements" are disallowed: This has to deliver
961 // the true picture of the buffer. (Asger)
962 // If position is -1, we get the layout font of the paragraph.
963 // If position is -2, we get the font of the manual label of the paragraph.
964 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
967 LyXLayout const & layout =
968 textclasslist.Style(current_view->buffer()->params.textclass,
970 LyXParagraph::size_type main_body = 0;
971 if (layout.labeltype == LABEL_MANUAL)
972 main_body = BeginningOfMainBody();
977 layoutfont = layout.labelfont;
979 layoutfont = layout.font;
980 tmpfont = GetFontSettings(pos);
981 tmpfont.realize(layoutfont);
983 // process layoutfont for pos == -1 and labelfont for pos < -1
985 tmpfont = layout.font;
987 tmpfont = layout.labelfont;
988 if (current_view->text->GetParDirection((LyXParagraph *)this) == LYX_DIR_RIGHT_TO_LEFT)
989 tmpfont.setDirection(LyXFont::RTL_DIR);
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();
1897 // ok, now copy the paragraph
1898 for (size_type i = 0; i <= pos_end; ++i) {
1899 the_next->CutIntoMinibuffer(i);
1900 InsertFromMinibuffer(pos_insert + i);
1903 // delete the next paragraph
1908 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1910 LyXParagraph * par = ParFromPos(pos);
1912 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1913 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1919 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1921 LyXParagraph * par = ParFromPos(pos);
1923 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1924 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1930 LyXTextClass::LayoutList::size_type LyXParagraph::GetLayout() const
1932 return FirstPhysicalPar()->layout;
1936 char LyXParagraph::GetDepth() const
1938 return FirstPhysicalPar()->depth;
1942 char LyXParagraph::GetAlign() const
1944 return FirstPhysicalPar()->align;
1948 string LyXParagraph::GetLabestring() const
1950 return FirstPhysicalPar()->labelstring;
1954 int LyXParagraph::GetFirstCounter(int i) const
1956 return FirstPhysicalPar()->counter_[i];
1960 // the next two functions are for the manual labels
1961 string LyXParagraph::GetLabelWidthString() const
1963 if (!FirstPhysicalPar()->labelwidthstring.empty())
1964 return FirstPhysicalPar()->labelwidthstring;
1966 return _("Senseless with this layout!");
1970 void LyXParagraph::SetLabelWidthString(string const & s)
1972 LyXParagraph * par = FirstPhysicalPar();
1974 par->labelwidthstring = s;
1978 void LyXParagraph::SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout)
1980 LyXParagraph * par = FirstPhysicalPar();
1981 LyXParagraph * ppar = 0;
1982 LyXParagraph * npar = 0;
1984 par->layout = new_layout;
1985 /* table stuff -- begin*/
1988 /* table stuff -- end*/
1989 if (par->pextra_type == PEXTRA_NONE) {
1990 if (par->Previous()) {
1991 ppar = par->Previous()->FirstPhysicalPar();
1994 && (ppar->depth > par->depth))
1995 ppar = ppar->Previous()->FirstPhysicalPar();
1998 npar = par->Next()->NextAfterFootnote();
2001 && (npar->depth > par->depth))
2002 npar = npar->Next()->NextAfterFootnote();
2004 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2006 p1 = ppar->pextra_width,
2007 p2 = ppar->pextra_widthp;
2008 ppar->SetPExtraType(ppar->pextra_type,
2009 p1.c_str(), p2.c_str());
2011 if ((par->pextra_type == PEXTRA_NONE) &&
2012 npar && (npar->pextra_type != PEXTRA_NONE)) {
2014 p1 = npar->pextra_width,
2015 p2 = npar->pextra_widthp;
2016 npar->SetPExtraType(npar->pextra_type,
2017 p1.c_str(), p2.c_str());
2023 void LyXParagraph::SetLayout(LyXTextClass::LayoutList::size_type new_layout)
2026 * par = FirstPhysicalPar(),
2030 par->layout = new_layout;
2031 par->labelwidthstring.clear();
2032 par->align = LYX_ALIGN_LAYOUT;
2033 par->added_space_top = VSpace(VSpace::NONE);
2034 par->added_space_bottom = VSpace(VSpace::NONE);
2035 /* table stuff -- begin*/
2038 /* table stuff -- end*/
2039 if (par->pextra_type == PEXTRA_NONE) {
2040 if (par->Previous()) {
2041 ppar = par->Previous()->FirstPhysicalPar();
2044 && (ppar->depth > par->depth))
2045 ppar = ppar->Previous()->FirstPhysicalPar();
2048 npar = par->Next()->NextAfterFootnote();
2051 && (npar->depth > par->depth))
2052 npar = npar->Next()->NextAfterFootnote();
2054 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2056 p1 = ppar->pextra_width,
2057 p2 = ppar->pextra_widthp;
2058 ppar->SetPExtraType(ppar->pextra_type,
2059 p1.c_str(), p2.c_str());
2061 if ((par->pextra_type == PEXTRA_NONE) &&
2062 npar && (npar->pextra_type != PEXTRA_NONE)) {
2064 p1 = npar->pextra_width,
2065 p2 = npar->pextra_widthp;
2066 npar->SetPExtraType(npar->pextra_type,
2067 p1.c_str(), p2.c_str());
2073 // if the layout of a paragraph contains a manual label, the beginning of the
2074 // main body is the beginning of the second word. This is what the par-
2075 // function returns. If the layout does not contain a label, the main
2076 // body always starts with position 0. This differentiation is necessary,
2077 // because there cannot be a newline or a blank <= the beginning of the
2078 // main body in TeX.
2080 int LyXParagraph::BeginningOfMainBody() const
2082 if (FirstPhysicalPar() != this)
2085 // Unroll the first two cycles of the loop
2086 // and remember the previous character to
2087 // remove unnecessary GetChar() calls
2090 && GetChar(i) != LyXParagraph::META_NEWLINE) {
2092 char previous_char, temp;
2094 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2095 // Yes, this ^ is supposed to be "= " not "=="
2098 && previous_char != ' '
2099 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2101 previous_char = temp;
2106 if (i == 0 && i == size() &&
2107 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2108 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2109 ++i; /* the cursor should not jump
2110 * to the main body if there
2116 LyXParagraph * LyXParagraph::DepthHook(int deth)
2118 LyXParagraph * newpar = this;
2123 newpar = newpar->FirstPhysicalPar()->Previous();
2124 } while (newpar && newpar->GetDepth() > deth
2125 && newpar->footnoteflag == footnoteflag);
2128 if (Previous() || GetDepth())
2129 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2133 return newpar->FirstPhysicalPar();
2137 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2139 LyXParagraph const * newpar = this;
2144 newpar = newpar->FirstPhysicalPar()->Previous();
2145 } while (newpar && newpar->GetDepth() > deth
2146 && newpar->footnoteflag == footnoteflag);
2149 if (Previous() || GetDepth())
2150 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2154 return newpar->FirstPhysicalPar();
2158 int LyXParagraph::AutoDeleteInsets()
2160 #ifdef NEW_INSETTABLE
2161 vector<size_type> tmpvec;
2163 for (InsetList::iterator it = insetlist.begin();
2164 it != insetlist.end(); ++it) {
2165 if ((*it).inset && (*it).inset->AutoDelete()) {
2166 tmpvec.push_back((*it).pos);
2170 for (vector<size_type>::const_iterator cit = tmpvec.begin();
2171 cit != tmpvec.end(); ++cit) {
2176 InsetTable * tmpi = insettable;
2177 InsetTable * tmpi2 = tmpi;
2183 if (tmpi2->inset->AutoDelete()) {
2188 lyxerr << "ERROR (LyXParagraph::AutoDeleteInsets): "
2189 "cannot auto-delete insets" << endl;
2197 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
2199 #ifdef NEW_INSETTABLE
2200 InsetList::iterator it2 = insetlist.end();
2201 for (InsetList::iterator it = insetlist.begin();
2202 it != insetlist.end(); ++it) {
2203 if ((*it).pos >= pos) {
2204 if (it2 == insetlist.end() || (*it).pos < (*it2).pos)
2208 if (it2 != insetlist.end()) {
2210 return (*it2).inset;
2214 InsetTable * tmpi = insettable;
2215 InsetTable * tmpi2 = 0;
2217 if (tmpi->pos >= pos) {
2218 if (!tmpi2 || tmpi->pos < tmpi2->pos)
2225 return tmpi2->inset;
2233 // returns -1 if inset not found
2234 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2237 #ifdef NEW_INSETTABLE
2238 for (InsetList::const_iterator cit = insetlist.begin();
2239 cit != insetlist.end(); ++cit) {
2240 if ((*cit).inset == inset) {
2245 InsetTable * tmpi = insettable;
2246 while (tmpi && tmpi->inset != inset) {
2249 if (tmpi && tmpi->inset)
2252 // Think about footnotes.
2253 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2254 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2256 NextAfterFootnote()->GetPositionOfInset(inset);
2258 return text.size() + 1 + further;
2264 void LyXParagraph::readSimpleWholeFile(istream & is)
2270 InsertChar(text.size(), c);
2275 LyXParagraph * LyXParagraph::TeXOnePar(string & file, TexRow & texrow,
2276 string & foot, TexRow & foot_texrow,
2279 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2280 LyXParagraph * par = next;
2281 LyXLayout const & style =
2282 textclasslist.Style(current_view->buffer()->params.textclass,
2285 bool further_blank_line = false;
2287 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2289 if (start_of_appendix) {
2290 file += "\\appendix\n";
2294 if (tex_code_break_column && style.isCommand()){
2299 if (pagebreak_top) {
2300 file += "\\newpage";
2301 further_blank_line = true;
2303 if (added_space_top.kind() != VSpace::NONE) {
2304 file += added_space_top.asLatexCommand();
2305 further_blank_line = true;
2309 file += "\\lyxline{\\" + getFont(0).latexSize() + '}';
2310 file += "\\vspace{-1\\parskip}";
2311 further_blank_line = true;
2314 if (further_blank_line){
2319 LyXDirection direction = current_view->text->GetParDirection((LyXParagraph *)this);
2320 LyXDirection global_direction = current_view->text->GetDocumentDirection();
2321 if (direction != global_direction) {
2322 if (direction == LYX_DIR_LEFT_TO_RIGHT)
2323 file += "{\\unsethebrew\n";
2325 file += "{\\sethebrew\n";
2330 switch (style.latextype) {
2333 file += style.latexname();
2334 file += style.latexparam();
2336 case LATEX_ITEM_ENVIRONMENT:
2338 bibkey->Latex(file, false);
2342 case LATEX_LIST_ENVIRONMENT:
2349 bool need_par = SimpleTeXOnePar(file, texrow);
2351 // Spit out footnotes
2352 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2353 && par->footnoteflag != footnoteflag) {
2354 par = par->TeXFootnote(file, texrow,
2355 foot, foot_texrow, foot_count);
2356 par->SimpleTeXOnePar(file, texrow);
2360 // Make sure that \\par is done with the font of the last
2361 // character if this has another size as the default.
2362 // This is necessary because LaTeX (and LyX on the screen)
2363 // calculates the space between the baselines according
2364 // to this font. (Matthias)
2365 LyXFont font = getFont(Last()-1);
2367 if (style.resfont.size() != font.size()) {
2369 file += font.latexSize();
2373 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2374 GetLayout()).isCommand()){
2375 if (style.resfont.size() != font.size()) {
2377 file += font.latexSize();
2381 } else if (style.resfont.size() != font.size()){
2382 file += "{\\" + font.latexSize() + " \\par}";
2385 if (direction != global_direction)
2388 switch (style.latextype) {
2389 case LATEX_ITEM_ENVIRONMENT:
2390 case LATEX_LIST_ENVIRONMENT:
2391 if (par && (depth < par->depth)) {
2396 case LATEX_ENVIRONMENT:
2397 // if its the last paragraph of the current environment
2398 // skip it otherwise fall through
2400 && (par->layout != layout
2401 || par->depth != depth
2402 || par->pextra_type != pextra_type))
2405 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2406 && footnotekind != LyXParagraph::FOOTNOTE
2407 && footnotekind != LyXParagraph::MARGIN
2411 // don't insert this if we would be adding it
2412 // before or after a table in a float. This
2413 // little trick is needed in order to allow
2414 // use of tables in \subfigures or \subtables.
2420 further_blank_line = false;
2422 file += "\\lyxline{\\" + getFont(Last()-1).latexSize() + '}';
2423 further_blank_line = true;
2426 if (added_space_bottom.kind() != VSpace::NONE) {
2427 file += added_space_bottom.asLatexCommand();
2428 further_blank_line = true;
2431 if (pagebreak_bottom) {
2432 file += "\\newpage";
2433 further_blank_line = true;
2436 if (further_blank_line){
2441 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2442 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2447 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2452 // This one spits out the text of the paragraph
2453 bool LyXParagraph::SimpleTeXOnePar(string & file, TexRow & texrow)
2455 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2458 return SimpleTeXOneTablePar(file, texrow);
2461 size_type main_body;
2463 bool return_value = false;
2465 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass, GetLayout());
2466 LyXFont basefont, last_font;
2468 // Maybe we have to create a optional argument.
2469 if (style.labeltype != LABEL_MANUAL)
2472 main_body = BeginningOfMainBody();
2474 if (main_body > 0) {
2476 basefont = getFont(-2); // Get label font
2478 basefont = getFont(-1); // Get layout font
2486 if (style.isCommand()) {
2489 } else if (align != LYX_ALIGN_LAYOUT) {
2492 return_value = true;
2496 // Which font is currently active?
2497 LyXFont running_font = basefont;
2498 // Do we have an open font change?
2499 bool open_font = false;
2501 texrow.start(this, 0);
2503 for (size_type i = 0; i < size(); ++i) {
2505 // First char in paragraph or after label?
2506 if (i == main_body && !IsDummy()) {
2507 if (main_body > 0) {
2509 column += running_font.latexWriteEndChanges(file, basefont, basefont);
2512 basefont = getFont(-1); // Now use the layout font
2513 running_font = basefont;
2517 if (style.isCommand()) {
2520 } else if (align != LYX_ALIGN_LAYOUT) {
2523 return_value = true;
2527 file += "\\noindent ";
2531 case LYX_ALIGN_NONE:
2532 case LYX_ALIGN_BLOCK:
2533 case LYX_ALIGN_LAYOUT:
2534 case LYX_ALIGN_SPECIAL: break;
2535 case LYX_ALIGN_LEFT:
2536 file += "\\raggedright ";
2539 case LYX_ALIGN_RIGHT:
2540 file += "\\raggedleft ";
2543 case LYX_ALIGN_CENTER:
2544 file += "\\centering ";
2552 // Fully instantiated font
2553 LyXFont font = getFont(i);
2554 last_font = running_font;
2556 // Spaces at end of font change are simulated to be
2557 // outside font change, i.e. we write "\textXX{text} "
2558 // rather than "\textXX{text }". (Asger)
2559 if (open_font && c == ' ' && i <= size() - 2
2560 && !getFont(i+1).equalExceptLatex(running_font)
2561 && !getFont(i+1).equalExceptLatex(font)) {
2562 font = getFont(i + 1);
2564 // We end font definition before blanks
2565 if (!font.equalExceptLatex(running_font) && open_font) {
2566 column += running_font.latexWriteEndChanges(file,
2568 (i == main_body-1) ? basefont : font);
2569 running_font = basefont;
2573 // Blanks are printed before start of fontswitch
2575 // Do not print the separation of the optional argument
2576 if (i != main_body - 1) {
2577 SimpleTeXBlanks(file, texrow, i,
2578 column, font, style);
2582 // Do we need to change font?
2583 if (!font.equalExceptLatex(running_font)
2584 && i != main_body-1) {
2585 column += font.latexWriteStartChanges(file, basefont, last_font);
2586 running_font = font;
2590 if (c == LyXParagraph::META_NEWLINE) {
2591 // newlines are handled differently here than
2592 // the default in SimpleTeXSpecialChars().
2593 if (!style.newline_allowed
2594 || font.latex() == LyXFont::ON) {
2598 column += running_font.latexWriteEndChanges(file, basefont, basefont);
2601 basefont = getFont(-1);
2602 running_font = basefont;
2603 if (font.family() ==
2604 LyXFont::TYPEWRITER_FAMILY) {
2610 texrow.start(this, i + 1);
2613 SimpleTeXSpecialChars(file, texrow,
2614 font, running_font, basefont,
2615 open_font, style, i, column, c);
2619 // If we have an open font definition, we have to close it
2621 running_font.latexWriteEndChanges(file, basefont, basefont);
2624 // Needed if there is an optional argument but no contents.
2625 if (main_body > 0 && main_body == size()) {
2627 return_value = false;
2630 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2631 return return_value;
2635 // This one spits out the text of a table paragraph
2636 bool LyXParagraph::SimpleTeXOneTablePar(string & file, TexRow & texrow)
2638 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2640 bool return_value = false;
2642 LyXLayout const & style =
2643 textclasslist.Style(current_view->buffer()->params.textclass,
2647 if (!IsDummy()) { // it is dummy if it is in a float!!!
2648 if (style.isCommand()) {
2651 } else if (align != LYX_ALIGN_LAYOUT) {
2654 return_value = true;
2657 file += "\\noindent ";
2661 case LYX_ALIGN_NONE:
2662 case LYX_ALIGN_BLOCK:
2663 case LYX_ALIGN_LAYOUT:
2664 case LYX_ALIGN_SPECIAL: break;
2665 case LYX_ALIGN_LEFT:
2666 file += "\\raggedright ";
2669 case LYX_ALIGN_RIGHT:
2670 file += "\\raggedleft ";
2673 case LYX_ALIGN_CENTER:
2674 file += "\\centering ";
2680 LyXFont basefont = getFont(-1); // Get layout font
2681 // Which font is currently active?
2682 LyXFont running_font = basefont;
2684 // Do we have an open font change?
2685 bool open_font = false;
2686 int current_cell_number = -1;
2687 int tmp = table->TexEndOfCell(file, current_cell_number);
2688 for (; tmp > 0 ; --tmp)
2691 texrow.start(this, 0);
2693 for (size_type i = 0; i < size(); ++i) {
2694 char c = GetChar(i);
2695 if (table->IsContRow(current_cell_number + 1)) {
2696 if (c == LyXParagraph::META_NEWLINE)
2697 ++current_cell_number;
2702 // Fully instantiated font
2703 LyXFont font = getFont(i);
2704 last_font = running_font;
2706 // Spaces at end of font change are simulated to be
2707 // outside font change.
2708 // i.e. we write "\textXX{text} " rather than
2709 // "\textXX{text }". (Asger)
2710 if (open_font && c == ' ' && i <= size() - 2
2711 && getFont(i+1) != running_font && getFont(i+1) != font) {
2712 font = getFont(i+1);
2715 // We end font definition before blanks
2716 if (font != running_font && open_font) {
2717 column += running_font.latexWriteEndChanges(file,
2719 running_font = basefont;
2722 // Blanks are printed before start of fontswitch
2724 SimpleTeXBlanks(file, texrow, i, column, font, style);
2726 // Do we need to change font?
2727 if (font != running_font) {
2728 column += font.latexWriteStartChanges(file, basefont, last_font);
2729 running_font = font;
2732 // Do we need to turn on LaTeX mode?
2733 if (font.latex() != running_font.latex()) {
2734 if (font.latex() == LyXFont::ON
2735 && style.needprotect) {
2736 file += "\\protect ";
2740 if (c == LyXParagraph::META_NEWLINE) {
2741 // special case for inside a table
2742 // different from default case in
2743 // SimpleTeXSpecialChars()
2745 column += running_font
2746 .latexWriteEndChanges(file, basefont, basefont);
2749 basefont = getFont(-1);
2750 running_font = basefont;
2751 ++current_cell_number;
2752 if (table->CellHasContRow(current_cell_number) >= 0) {
2753 TeXContTableRows(file, i + 1,
2754 current_cell_number,
2757 // if this cell follow only ContRows till end don't
2758 // put the EndOfCell because it is put after the
2760 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2761 --current_cell_number;
2764 int tmp = table->TexEndOfCell(file,
2765 current_cell_number);
2768 } else if (tmp < 0) {
2774 texrow.start(this, i + 1);
2776 SimpleTeXSpecialChars(file, texrow,
2777 font, running_font, basefont,
2778 open_font, style, i, column, c);
2782 // If we have an open font definition, we have to close it
2784 running_font.latexWriteEndChanges(file, basefont, basefont);
2786 ++current_cell_number;
2787 tmp = table->TexEndOfCell(file, current_cell_number);
2788 for (; tmp > 0; --tmp)
2790 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2791 return return_value;
2795 // This one spits out the text off ContRows in tables
2796 bool LyXParagraph::TeXContTableRows(string & file,
2797 LyXParagraph::size_type i,
2798 int current_cell_number,
2799 int & column, TexRow & texrow)
2801 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2807 bool return_value = false;
2808 LyXLayout const & style =
2809 textclasslist.Style(current_view->buffer()->params.textclass,
2811 LyXFont basefont = getFont(-1); // Get layout font
2813 // Which font is currently active?
2814 LyXFont running_font = basefont;
2815 // Do we have an open font change?
2816 bool open_font = false;
2818 size_type lastpos = i;
2819 int cell = table->CellHasContRow(current_cell_number);
2820 ++current_cell_number;
2822 // first find the right position
2824 for (; (i < size()) && (current_cell_number<cell); ++i) {
2826 if (c == LyXParagraph::META_NEWLINE)
2827 ++current_cell_number;
2831 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2835 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2840 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2844 // Fully instantiated font
2845 LyXFont font = getFont(i);
2846 last_font = running_font;
2848 // Spaces at end of font change are simulated to
2849 // be outside font change. i.e. we write
2850 // "\textXX{text} " rather than "\textXX{text }".
2852 if (open_font && c == ' ' && i <= size() - 2
2853 && getFont(i + 1) != running_font
2854 && getFont(i + 1) != font) {
2855 font = getFont(i + 1);
2858 // We end font definition before blanks
2859 if (font != running_font && open_font) {
2860 column += running_font.latexWriteEndChanges(file, basefont, font);
2861 running_font = basefont;
2864 // Blanks are printed before start of fontswitch
2866 SimpleTeXBlanks(file, texrow, i,
2867 column, font, style);
2869 // Do we need to change font?
2870 if (font != running_font) {
2872 font.latexWriteStartChanges(file,
2873 basefont, last_font);
2874 running_font = font;
2877 // Do we need to turn on LaTeX mode?
2878 if (font.latex() != running_font.latex()) {
2879 if (font.latex() == LyXFont::ON
2880 && style.needprotect)
2882 file += "\\protect ";
2886 SimpleTeXSpecialChars(file, texrow, font,
2887 running_font, basefont,
2888 open_font, style, i, column, c);
2890 // If we have an open font definition, we have to close it
2892 running_font.latexWriteEndChanges(file, basefont, basefont);
2895 basefont = getFont(-1);
2896 running_font = basefont;
2897 cell = table->CellHasContRow(current_cell_number);
2899 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2900 return return_value;
2904 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2906 bool retval = false;
2908 case LyXParagraph::META_HFILL:
2909 sgml_string.clear();
2911 case LyXParagraph::META_PROTECTED_SEPARATOR:
2914 case LyXParagraph::META_NEWLINE:
2918 sgml_string = "&";
2921 sgml_string = "<";
2924 sgml_string = ">";
2927 sgml_string = "$";
2930 sgml_string = "#";
2933 sgml_string = "%";
2936 sgml_string = "[";
2939 sgml_string = "]";
2942 sgml_string = "{";
2945 sgml_string = "}";
2948 sgml_string = "˜";
2951 sgml_string = """;
2954 sgml_string = "\";
2960 case '\0': // Ignore :-)
2961 sgml_string.clear();
2971 void LyXParagraph::SimpleDocBookOneTablePar(string & file, string & extra,
2972 int & desc_on, int depth)
2975 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2977 LyXFont font1, font2;
2980 size_type main_body;
2981 string emph = "emphasis";
2982 bool emph_flag = false;
2984 LyXLayout const & style =
2985 textclasslist.Style(current_view->buffer()->params.textclass,
2988 if (style.labeltype != LABEL_MANUAL)
2991 main_body = BeginningOfMainBody();
2993 // Gets paragraph main font.
2995 font1 = style.labelfont;
2999 int char_line_count = depth;
3000 addNewlineAndDepth(file, depth);
3001 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3002 file += "<INFORMALTABLE>";
3003 addNewlineAndDepth(file, ++depth);
3005 int current_cell_number = -1;
3006 int tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
3008 // Parsing main loop.
3009 for (size_type i = 0; i < size(); ++i) {
3011 if (table->IsContRow(current_cell_number+1)) {
3012 if (c == LyXParagraph::META_NEWLINE)
3013 ++current_cell_number;
3018 // Fully instantiated font
3021 // Handle <emphasis> tag.
3022 if (font1.emph() != font2.emph() && i) {
3023 if (font2.emph() == LyXFont::ON) {
3024 file += "<emphasis>";
3026 } else if (emph_flag) {
3027 file += "</emphasis>";
3031 if (c == LyXParagraph::META_NEWLINE) {
3032 // We have only to control for emphasis open here!
3034 file += "</emphasis>";
3037 font1 = font2 = getFont(-1);
3038 ++current_cell_number;
3039 if (table->CellHasContRow(current_cell_number) >= 0) {
3040 DocBookContTableRows(file, extra, desc_on, i+1,
3041 current_cell_number,
3044 // if this cell follow only ContRows till end don't
3045 // put the EndOfCell because it is put after the
3047 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3048 --current_cell_number;
3051 tmp = table->DocBookEndOfCell(file,
3052 current_cell_number,
3057 } else if (c == LyXParagraph::META_INSET) {
3058 inset = GetInset(i);
3060 inset->DocBook(tmp_out);
3062 // This code needs some explanation:
3063 // Two insets are treated specially
3064 // label if it is the first element in a
3065 // command paragraph
3067 // graphics inside tables or figure floats
3069 // title (the equivalente in latex for this
3071 // and title should come first
3074 if(desc_on != 3 || i != 0) {
3075 if(tmp_out[0] == '@') {
3077 extra += frontStrip(tmp_out,
3080 file += frontStrip(tmp_out,
3085 } else if (font2.latex() == LyXFont::ON) {
3086 // "TeX"-Mode on == > SGML-Mode on.
3092 if (linuxDocConvertChar(c, sgml_string)
3093 && !style.free_spacing) {
3094 // in freespacing mode, spaces are
3095 // non-breaking characters
3100 file += "</term><listitem><para>";
3106 file += sgml_string;
3112 // Needed if there is an optional argument but no contents.
3113 if (main_body > 0 && main_body == size()) {
3118 file += "</emphasis>";
3121 ++current_cell_number;
3122 tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
3123 // Resets description flag correctly.
3126 // <term> not closed...
3130 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3131 file += "</INFORMALTABLE>";
3133 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3138 void LyXParagraph::DocBookContTableRows(string & file, string & extra,
3140 LyXParagraph::size_type i,
3141 int current_cell_number, int &column)
3146 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3151 string emph= "emphasis";
3152 bool emph_flag= false;
3153 int char_line_count= 0;
3155 LyXLayout const & style =
3156 textclasslist.Style(current_view->buffer()->params.textclass,
3159 size_type main_body;
3160 if (style.labeltype != LABEL_MANUAL)
3163 main_body = BeginningOfMainBody();
3165 // Gets paragraph main font.
3168 font1 = style.labelfont;
3172 size_type lastpos = i;
3173 int cell = table->CellHasContRow(current_cell_number);
3174 ++current_cell_number;
3176 // first find the right position
3178 for (; i < size() && current_cell_number < cell; ++i) {
3180 if (c == LyXParagraph::META_NEWLINE)
3181 ++current_cell_number;
3185 // I don't know how to handle this so I comment it
3186 // for the moment (Jug)
3187 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3188 // file += " \\\\\n";
3191 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3196 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3200 // Fully instantiated font
3203 // Handle <emphasis> tag.
3204 if (font1.emph() != font2.emph() && i) {
3205 if (font2.emph() == LyXFont::ON) {
3206 file += "<emphasis>";
3208 } else if (emph_flag) {
3209 file += "</emphasis>";
3213 if (c == LyXParagraph::META_INSET) {
3214 inset = GetInset(i);
3216 inset->DocBook(tmp_out);
3218 // This code needs some explanation:
3219 // Two insets are treated specially
3220 // label if it is the first element in a
3221 // command paragraph
3223 // graphics inside tables or figure floats
3224 // can't go on title (the equivalente in
3225 // latex for this case is caption and title
3226 // should come first
3229 if(desc_on != 3 || i != 0) {
3230 if(tmp_out[0] == '@') {
3232 extra += frontStrip(tmp_out, '@');
3234 file += frontStrip(tmp_out, '@');
3238 } else if (font2.latex() == LyXFont::ON) {
3239 // "TeX"-Mode on == > SGML-Mode on.
3245 if (linuxDocConvertChar(c, sgml_string)
3246 && !style.free_spacing) {
3247 // in freespacing mode, spaces are
3248 // non-breaking characters
3253 file += "</term><listitem><para>";
3259 file += sgml_string;
3263 // we have only to control for emphasis open here!
3265 file += "</emphasis>";
3268 font1 = font2 = getFont(-1);
3269 cell = table->CellHasContRow(current_cell_number);
3271 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3275 void LyXParagraph::SimpleTeXBlanks(string & file, TexRow & texrow,
3276 LyXParagraph::size_type const i,
3277 int & column, LyXFont const & font,
3278 LyXLayout const & style)
3280 if (column > tex_code_break_column
3282 && GetChar(i - 1) != ' '
3284 // In LaTeX mode, we don't want to
3285 // break lines since some commands
3287 && ! (font.latex() == LyXFont::ON)
3288 // same in FreeSpacing mode
3289 && !style.free_spacing
3290 // In typewriter mode, we want to avoid
3291 // ! . ? : at the end of a line
3292 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3293 && (GetChar(i-1) == '.'
3294 || GetChar(i-1) == '?'
3295 || GetChar(i-1) == ':'
3296 || GetChar(i-1) == '!'))) {
3297 if (tex_code_break_column == 0) {
3298 // in batchmode we need LaTeX to still
3299 // see it as a space not as an extra '\n'
3305 texrow.start(this, i+1);
3307 } else if (font.latex() == LyXFont::OFF) {
3308 if (style.free_spacing) {
3317 void LyXParagraph::SimpleTeXSpecialChars(string & file, TexRow & texrow,
3319 LyXFont & running_font,
3322 LyXLayout const & style,
3323 LyXParagraph::size_type & i,
3324 int & column, char const c)
3326 // Two major modes: LaTeX or plain
3327 // Handle here those cases common to both modes
3328 // and then split to handle the two modes separately.
3330 case LyXParagraph::META_INSET: {
3331 Inset * inset = GetInset(i);
3334 int len = file.length();
3335 if ( (inset->LyxCode() == Inset::GRAPHICS_CODE
3336 || inset->LyxCode() == Inset::MATH_CODE)
3337 && current_view->text->GetFontDirection(running_font)
3338 == LYX_DIR_RIGHT_TO_LEFT) {
3342 int tmp = inset->Latex(file, style.isCommand());
3349 column += file.length() - len;
3358 case LyXParagraph::META_NEWLINE:
3360 column += running_font.latexWriteEndChanges(file,
3361 basefont, basefont);
3364 basefont = getFont(-1);
3365 running_font = basefont;
3368 case LyXParagraph::META_HFILL:
3369 file += "\\hfill{}";
3374 // And now for the special cases within each mode
3375 // Are we in LaTeX mode?
3376 if (font.latex() == LyXFont::ON) {
3377 // at present we only have one option
3378 // but I'll leave it as a switch statement
3379 // so its simpler to extend. (ARRae)
3381 case LyXParagraph::META_PROTECTED_SEPARATOR:
3386 // make sure that we will not print
3387 // error generating chars to the tex
3388 // file. This test would not be needed
3389 // if it were done in the buffer
3397 // Plain mode (i.e. not LaTeX)
3399 case LyXParagraph::META_PROTECTED_SEPARATOR:
3404 file += "\\textbackslash{}";
3408 case '°': case '±': case '²': case '³':
3409 case '×': case '÷': case '¹': case 'ª':
3410 case 'º': case '¬': case 'µ':
3411 if (current_view->buffer()->params.inputenc == "latin1") {
3412 file += "\\ensuremath{";
3421 case '|': case '<': case '>':
3422 // In T1 encoding, these characters exist
3423 if (lyxrc->fontenc == "T1") {
3425 //... but we should avoid ligatures
3426 if ((c == '>' || c == '<')
3428 && GetChar(i+1) == c){
3429 file += "\\textcompwordmark{}";
3434 // Typewriter font also has them
3435 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3439 // Otherwise, we use what LaTeX
3443 file += "\\textless{}";
3447 file += "\\textgreater{}";
3451 file += "\\textbar{}";
3457 case '-': // "--" in Typewriter mode -> "-{}-"
3459 && GetChar(i + 1) == '-'
3460 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3469 file += "\\char`\\\"{}";
3474 if (current_view->buffer()->params.inputenc == "default") {
3475 file += "\\pounds{}";
3483 case '%': case '#': case '{':
3491 file += "\\textasciitilde{}";
3496 file += "\\textasciicircum{}";
3500 case '*': case '[': case ']':
3501 // avoid being mistaken for optional arguments
3509 // Blanks are printed before font switching.
3510 // Sure? I am not! (try nice-latex)
3511 // I am sure it's correct. LyX might be smarter
3512 // in the future, but for now, nothing wrong is
3517 /* idea for labels --- begin*/
3521 && font.family() != LyXFont::TYPEWRITER_FAMILY
3522 && GetChar(i + 1) == 'y'
3523 && GetChar(i + 2) == 'X') {
3531 && font.family() != LyXFont::TYPEWRITER_FAMILY
3532 && GetChar(i + 1) == 'e'
3533 && GetChar(i + 2) == 'X') {
3538 // Check for "LaTeX2e"
3541 && font.family() != LyXFont::TYPEWRITER_FAMILY
3542 && GetChar(i + 1) == 'a'
3543 && GetChar(i + 2) == 'T'
3544 && GetChar(i + 3) == 'e'
3545 && GetChar(i + 4) == 'X'
3546 && GetChar(i + 5) == '2'
3547 && GetChar(i + 6) == 'e') {
3548 file += "\\LaTeXe{}";
3552 // Check for "LaTeX"
3555 && font.family() != LyXFont::TYPEWRITER_FAMILY
3556 && GetChar(i + 1) == 'a'
3557 && GetChar(i + 2) == 'T'
3558 && GetChar(i + 3) == 'e'
3559 && GetChar(i + 4) == 'X') {
3560 file += "\\LaTeX{}";
3563 /* idea for labels --- end*/
3564 } else if (c != '\0') {
3574 bool LyXParagraph::RoffContTableRows(ostream & os,
3575 LyXParagraph::size_type i,
3581 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3586 string fname2 = TmpFileName(string(), "RAT2");
3588 int cell = table->CellHasContRow(actcell);
3591 // first find the right position
3593 for (; i < size() && actcell < cell; ++i) {
3595 if (c == LyXParagraph::META_NEWLINE)
3600 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3603 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3605 font2 = GetFontSettings(i);
3606 if (font1.latex() != font2.latex()) {
3607 if (font2.latex() != LyXFont::OFF)
3612 case LyXParagraph::META_INSET:
3613 if ((inset = GetInset(i))) {
3614 fstream fs(fname2.c_str(),
3617 WriteAlert(_("LYX_ERROR:"),
3618 _("Cannot open temporary file:"),
3622 inset->Latex(fs, -1);
3635 case LyXParagraph::META_NEWLINE:
3637 case LyXParagraph::META_HFILL:
3639 case LyXParagraph::META_PROTECTED_SEPARATOR:
3648 lyxerr.debug() << "RoffAsciiTable: "
3649 "NULL char in structure."
3654 cell = table->CellHasContRow(actcell);
3660 LyXParagraph * LyXParagraph::TeXDeeper(string & file, TexRow & texrow,
3661 string & foot, TexRow & foot_texrow,
3664 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3665 LyXParagraph * par = this;
3667 while (par && par->depth == depth) {
3669 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3670 if (textclasslist.Style(current_view->buffer()->params.textclass,
3671 par->layout).isEnvironment()
3672 || par->pextra_type != PEXTRA_NONE)
3674 par = par->TeXEnvironment(file, texrow,
3678 par = par->TeXOnePar(file, texrow,
3683 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3689 LyXParagraph * LyXParagraph::TeXEnvironment(string & file, TexRow & texrow,
3691 TexRow & foot_texrow,
3694 bool eindent_open = false;
3695 bool foot_this_level = false;
3696 // flags when footnotetext should be appended to file.
3697 static bool minipage_open = false;
3698 static int minipage_open_depth = 0;
3699 char par_sep = current_view->buffer()->params.paragraph_separation;
3701 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3703 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3705 LyXLayout const & style =
3706 textclasslist.Style(current_view->buffer()->params.textclass,
3709 if (pextra_type == PEXTRA_INDENT) {
3710 if (!pextra_width.empty()) {
3711 file += "\\begin{LyXParagraphIndent}{"
3712 + pextra_width + "}\n";
3714 //float ib = atof(pextra_widthp.c_str())/100;
3715 // string can't handle floats at present (971109)
3716 // so I'll do a conversion by hand knowing that
3717 // the limits are 0.0 to 1.0. ARRae.
3718 file += "\\begin{LyXParagraphIndent}{";
3719 switch (pextra_widthp.length()) {
3725 file += pextra_widthp;
3729 file += pextra_widthp;
3731 file += "\\columnwidth}\n";
3734 eindent_open = true;
3736 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3737 if (pextra_hfill && Previous() &&
3738 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3739 file += "\\hfill{}\n";
3742 if (par_sep == BufferParams::PARSEP_INDENT) {
3743 file += "{\\setlength\\parindent{0pt}\n";
3746 file += "\\begin{minipage}";
3747 switch(pextra_alignment) {
3748 case MINIPAGE_ALIGN_TOP:
3751 case MINIPAGE_ALIGN_MIDDLE:
3754 case MINIPAGE_ALIGN_BOTTOM:
3758 if (!pextra_width.empty()) {
3760 file += pextra_width + "}\n";
3762 //float ib = atof(par->pextra_width.c_str())/100;
3763 // string can't handle floats at present
3764 // so I'll do a conversion by hand knowing that
3765 // the limits are 0.0 to 1.0. ARRae.
3767 switch (pextra_widthp.length()) {
3773 file += pextra_widthp;
3777 file += pextra_widthp;
3779 file += "\\columnwidth}\n";
3782 if (par_sep == BufferParams::PARSEP_INDENT) {
3783 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3786 minipage_open = true;
3787 minipage_open_depth = depth;
3790 #ifdef WITH_WARNINGS
3791 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3792 //I disabled it because it breaks when lists span on several
3795 if (style.isEnvironment()){
3796 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3797 #ifdef FANCY_FOOTNOTE_CODE
3798 if (foot_count < 0) {
3799 // flag that footnote[mark][text] should be
3800 // used for any footnotes from now on
3802 foot_this_level = true;
3805 file += "\\begin{" + style.latexname() + "}{"
3806 + labelwidthstring + "}\n";
3807 } else if (style.labeltype == LABEL_BIBLIO) {
3809 file += "\\begin{" + style.latexname() + "}{"
3810 + bibitemWidthest() + "}\n";
3811 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3812 #ifdef FANCY_FOOTNOTE_CODE
3813 if (foot_count < 0) {
3814 // flag that footnote[mark][text] should be
3815 // used for any footnotes from now on
3817 foot_this_level = true;
3820 file += "\\begin{" + style.latexname() + '}'
3821 + style.latexparam() + '\n';
3823 file += "\\begin{" + style.latexname() + '}'
3824 + style.latexparam() + '\n';
3827 LyXParagraph * par = this;
3829 par = par->TeXOnePar(file, texrow,
3830 foot, foot_texrow, foot_count);
3832 if (minipage_open && par && !style.isEnvironment() &&
3833 (par->pextra_type == PEXTRA_MINIPAGE) &&
3834 par->pextra_start_minipage) {
3835 file += "\\end{minipage}\n";
3837 if (par_sep == BufferParams::PARSEP_INDENT) {
3841 minipage_open = false;
3843 if (par && par->depth > depth) {
3844 if (textclasslist.Style(current_view->buffer()->params.textclass,
3845 par->layout).isParagraph()
3847 && !suffixIs(file, "\n\n")) {
3848 // There should be at least one '\n' already
3849 // but we need there to be two for Standard
3850 // paragraphs that are depth-increment'ed to be
3851 // output correctly. However, tables can
3852 // also be paragraphs so don't adjust them.
3857 par = par->TeXDeeper(file, texrow,
3858 foot, foot_texrow, foot_count);
3860 if (par && par->layout == layout && par->depth == depth &&
3861 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3862 if (par->pextra_hfill && par->Previous() &&
3863 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3864 file += "\\hfill{}\n";
3867 if (par_sep == BufferParams::PARSEP_INDENT) {
3868 file += "{\\setlength\\parindent{0pt}\n";
3871 file += "\\begin{minipage}";
3872 switch(par->pextra_alignment) {
3873 case MINIPAGE_ALIGN_TOP:
3876 case MINIPAGE_ALIGN_MIDDLE:
3879 case MINIPAGE_ALIGN_BOTTOM:
3883 if (!par->pextra_width.empty()) {
3885 file += par->pextra_width;
3888 //float ib = atof(par->pextra_widthp.c_str())/100;
3889 // string can't handle floats at present
3890 // so I'll do a conversion by hand knowing that
3891 // the limits are 0.0 to 1.0. ARRae.
3893 switch (par->pextra_widthp.length()) {
3899 file += par->pextra_widthp;
3903 file += par->pextra_widthp;
3905 file += "\\columnwidth}\n";
3908 if (par_sep == BufferParams::PARSEP_INDENT) {
3909 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3912 minipage_open = true;
3913 minipage_open_depth = par->depth;
3916 && par->layout == layout
3917 && par->depth == depth
3918 && par->pextra_type == pextra_type);
3920 if (style.isEnvironment()) {
3921 file += "\\end{" + style.latexname() + '}';
3922 // maybe this should go after the minipage closes?
3923 if (foot_this_level) {
3924 if (foot_count >= 1) {
3925 if (foot_count > 1) {
3926 file += "\\addtocounter{footnote}{-";
3927 file += tostr(foot_count - 1);
3931 texrow += foot_texrow;
3933 foot_texrow.reset();
3938 if (minipage_open && (minipage_open_depth == depth) &&
3939 (!par || par->pextra_start_minipage ||
3940 par->pextra_type != PEXTRA_MINIPAGE)) {
3941 file += "\\end{minipage}\n";
3943 if (par_sep == BufferParams::PARSEP_INDENT) {
3947 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3948 file += "\\medskip\n\n";
3952 minipage_open = false;
3955 file += "\\end{LyXParagraphIndent}\n";
3958 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3959 && par->pextra_hfill)) {
3963 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3964 return par; // ale970302
3968 LyXParagraph * LyXParagraph::TeXFootnote(string & file, TexRow & texrow,
3969 string & foot, TexRow & foot_texrow,
3972 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3973 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3974 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3975 "No footnote!" << endl;
3977 LyXParagraph * par = this;
3978 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass,
3979 previous->GetLayout());
3981 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3982 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3983 "Float other than footnote in command"
3984 " with moving argument is illegal" << endl;
3987 if (footnotekind != LyXParagraph::FOOTNOTE
3988 && footnotekind != LyXParagraph::MARGIN
3990 && !suffixIs(file, '\n')) {
3991 // we need to ensure that real floats like tables and figures
3992 // have their \begin{} on a new line otherwise we can get
3993 // incorrect results when using the endfloat.sty package
3994 // especially if two floats follow one another. ARRae 981022
3995 // NOTE: if the file is length 0 it must have just been
3996 // written out so we assume it ended with a '\n'
4001 BufferParams * params = ¤t_view->buffer()->params;
4002 bool footer_in_body = true;
4003 switch (footnotekind) {
4004 case LyXParagraph::FOOTNOTE:
4005 if (style.intitle) {
4006 file += "\\thanks{\n";
4007 footer_in_body = false;
4009 if (foot_count == -1) {
4010 // we're at depth 0 so we can use:
4011 file += "\\footnote{%\n";
4012 footer_in_body = false;
4014 file += "\\footnotemark{}%\n";
4016 // we only need this when there are
4017 // multiple footnotes
4018 foot += "\\stepcounter{footnote}";
4020 foot += "\\footnotetext{%\n";
4021 foot_texrow.start(this, 0);
4022 foot_texrow.newline();
4027 case LyXParagraph::MARGIN:
4028 file += "\\marginpar{\n";
4030 case LyXParagraph::FIG:
4031 if (pextra_type == PEXTRA_FLOATFLT
4032 && (!pextra_width.empty()
4033 || !pextra_widthp.empty())) {
4035 if (!pextra_width.empty())
4036 sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
4037 pextra_width.c_str());
4040 "\\begin{floatingfigure}{%f\\textwidth}\n",
4041 atoi(pextra_widthp.c_str())/100.0);
4044 file += "\\begin{figure}";
4045 if (!params->float_placement.empty()) {
4047 file += params->float_placement;
4054 case LyXParagraph::TAB:
4055 file += "\\begin{table}";
4056 if (!params->float_placement.empty()) {
4058 file += params->float_placement;
4064 case LyXParagraph::WIDE_FIG:
4065 file += "\\begin{figure*}";
4066 if (!params->float_placement.empty()) {
4068 file += params->float_placement;
4074 case LyXParagraph::WIDE_TAB:
4075 file += "\\begin{table*}";
4076 if (!params->float_placement.empty()) {
4078 file += params->float_placement;
4084 case LyXParagraph::ALGORITHM:
4085 file += "\\begin{algorithm}\n";
4090 if (footnotekind != LyXParagraph::FOOTNOTE
4091 || !footer_in_body) {
4092 // Process text for all floats except footnotes in body
4094 LyXLayout const & style =
4095 textclasslist.Style(current_view->buffer()->params.textclass,
4098 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4100 if (style.isEnvironment()
4101 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4102 // Allows the use of minipages within float
4103 // environments. Shouldn't be circular because
4104 // we don't support footnotes inside
4105 // floats (yet). ARRae
4106 par = par->TeXEnvironment(file, texrow,
4110 par = par->TeXOnePar(file, texrow,
4115 if (par && !par->IsDummy() && par->depth > depth) {
4116 par = par->TeXDeeper(file, texrow,
4120 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4122 // process footnotes > depth 0 or in environments separately
4123 // NOTE: Currently don't support footnotes within footnotes
4124 // even though that is possible using the \footnotemark
4126 TexRow dummy_texrow;
4127 int dummy_count = 0;
4129 LyXLayout const & style =
4130 textclasslist.Style(current_view->buffer()->params.textclass,
4133 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4135 if (style.isEnvironment()
4136 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4137 // Allows the use of minipages within float
4138 // environments. Shouldn't be circular because
4139 // we don't support footnotes inside
4140 // floats (yet). ARRae
4141 par = par->TeXEnvironment(foot, foot_texrow,
4142 dummy, dummy_texrow,
4145 par = par->TeXOnePar(foot, foot_texrow,
4146 dummy, dummy_texrow,
4150 if (par && !par->IsDummy() && par->depth > depth) {
4151 par = par->TeXDeeper(foot, foot_texrow,
4152 dummy, dummy_texrow,
4156 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4158 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4159 "Footnote in a Footnote -- not supported"
4164 switch (footnotekind) {
4165 case LyXParagraph::FOOTNOTE:
4166 if (footer_in_body) {
4167 // This helps tell which of the multiple
4168 // footnotetexts an error was in.
4170 foot_texrow.newline();
4175 case LyXParagraph::MARGIN:
4178 case LyXParagraph::FIG:
4179 if (pextra_type == PEXTRA_FLOATFLT
4180 && (!pextra_width.empty()
4181 || !pextra_widthp.empty()))
4182 file += "\\end{floatingfigure}";
4184 file += "\\end{figure}";
4186 case LyXParagraph::TAB:
4187 file += "\\end{table}";
4189 case LyXParagraph::WIDE_FIG:
4190 file += "\\end{figure*}";
4192 case LyXParagraph::WIDE_TAB:
4193 file += "\\end{table*}";
4195 case LyXParagraph::ALGORITHM:
4196 file += "\\end{algorithm}";
4200 if (footnotekind != LyXParagraph::FOOTNOTE
4201 && footnotekind != LyXParagraph::MARGIN) {
4202 // we need to ensure that real floats like tables and figures
4203 // have their \end{} on a line of their own otherwise we can
4204 // get incorrect results when using the endfloat.sty package.
4209 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4214 void LyXParagraph::SetPExtraType(int type, char const * width,
4215 char const * widthp)
4218 pextra_width = width;
4219 pextra_widthp = widthp;
4221 if (textclasslist.Style(current_view->buffer()->params.textclass,
4222 layout).isEnvironment()) {
4227 while (par && (par->layout == layout)
4228 && (par->depth == depth)) {
4230 par = par->Previous();
4232 par = par->FirstPhysicalPar();
4233 while (par && par->depth > depth) {
4234 par = par->Previous();
4236 par = par->FirstPhysicalPar();
4240 while (par && (par->layout == layout)
4241 && (par->depth == depth)) {
4242 par->pextra_type = type;
4243 par->pextra_width = width;
4244 par->pextra_widthp = widthp;
4245 par = par->NextAfterFootnote();
4246 if (par && (par->depth > depth))
4247 par->SetPExtraType(type, width, widthp);
4248 while (par && ((par->depth > depth) || par->IsDummy()))
4249 par = par->NextAfterFootnote();
4255 void LyXParagraph::UnsetPExtraType()
4257 if (pextra_type == PEXTRA_NONE)
4260 pextra_type = PEXTRA_NONE;
4261 pextra_width.clear();
4262 pextra_widthp.clear();
4264 if (textclasslist.Style(current_view->buffer()->params.textclass,
4265 layout).isEnvironment()) {
4270 while (par && (par->layout == layout)
4271 && (par->depth == depth)) {
4273 par = par->Previous();
4275 par = par->FirstPhysicalPar();
4276 while (par && par->depth > depth) {
4277 par = par->Previous();
4279 par = par->FirstPhysicalPar();
4283 while (par && (par->layout == layout)
4284 && (par->depth == depth)) {
4285 par->pextra_type = PEXTRA_NONE;
4286 par->pextra_width.clear();
4287 par->pextra_widthp.clear();
4288 par = par->NextAfterFootnote();
4289 if (par && (par->depth > depth))
4290 par->UnsetPExtraType();
4291 while (par && ((par->depth > depth) || par->IsDummy()))
4292 par = par->NextAfterFootnote();
4298 bool LyXParagraph::IsHfill(size_type pos) const
4300 return IsHfillChar(GetChar(pos));
4304 bool LyXParagraph::IsInset(size_type pos) const
4306 return IsInsetChar(GetChar(pos));
4310 bool LyXParagraph::IsFloat(size_type pos) const
4312 return IsFloatChar(GetChar(pos));
4316 bool LyXParagraph::IsNewline(size_type pos) const
4320 tmp = IsNewlineChar(GetChar(pos));
4325 bool LyXParagraph::IsSeparator(size_type pos) const
4327 return IsSeparatorChar(GetChar(pos));
4331 bool LyXParagraph::IsLineSeparator(size_type pos) const
4333 return IsLineSeparatorChar(GetChar(pos));
4337 bool LyXParagraph::IsKomma(size_type pos) const
4339 return IsKommaChar(GetChar(pos));
4343 /// Used by the spellchecker
4344 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4346 unsigned char c = GetChar(pos);
4347 if (IsLetterChar(c))
4349 // '\0' is not a letter, allthough every string contains "" (below)
4352 // We want to pass the ' and escape chars to ispell
4353 string extra = lyxrc->isp_esc_chars + '\'';
4357 return contains(extra, ch);
4361 bool LyXParagraph::IsWord(size_type pos ) const
4363 return IsWordChar(GetChar(pos)) ;