1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
20 #include "lyxparagraph.h"
21 #include "support/textutils.h"
24 #include "tex-strings.h"
25 #include "bufferparams.h"
26 #include "support/FileInfo.h"
27 #include "support/LAssert.h"
29 #include "LaTeXFeatures.h"
30 #include "insets/insetinclude.h"
31 #include "insets/insetbib.h"
32 #include "support/filetools.h"
33 #include "lyx_gui_misc.h"
35 #include "support/lyxmanip.h"
42 int tex_code_break_column = 72; // needs non-zero initialization. set later.
43 // this is a bad idea, but how can LyXParagraph find its buffer to get
44 // parameters? (JMarc)
45 extern BufferView * current_view;
49 extern string bibitemWidthest(Painter &);
51 // this is a minibuffer
52 static char minibuffer_char;
53 static LyXFont minibuffer_font;
54 static Inset * minibuffer_inset;
57 // Initialization of the counter for the paragraph id's,
58 // declared in lyxparagraph.h
59 unsigned int LyXParagraph::paragraph_id = 0;
62 LyXParagraph::LyXParagraph()
64 text.reserve(500); // is this number too big?
66 for (int i = 0; i < 10; ++i) setCounter(i , 0);
72 footnoteflag = LyXParagraph::NO_FOOTNOTE;
73 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
75 align = LYX_ALIGN_BLOCK;
77 /* table stuff -- begin*/
79 /* table stuff -- end*/
82 bibkey = 0; // ale970302
87 // This konstruktor inserts the new paragraph in a list.
88 LyXParagraph::LyXParagraph(LyXParagraph * par)
91 par->text.resize(par->text.size());
93 for (int i = 0; i < 10; ++i) setCounter(i, 0);
97 // double linked list begin
100 next->previous = this;
102 previous->next = this;
104 footnoteflag = LyXParagraph::NO_FOOTNOTE;
105 footnotekind = LyXParagraph::FOOTNOTE;
107 /* table stuff -- begin*/
109 /* table stuff -- end*/
111 id_ = paragraph_id++;
113 bibkey = 0; // ale970302
119 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
120 char footflag, char dth) const
122 LyXFont font1, font2;
127 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
129 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
131 // The beginning or the end of a footnote environment?
132 if (footflag != footnoteflag) {
133 footflag = footnoteflag;
135 os << "\n\\begin_float "
136 << string_footnotekinds[footnotekind]
139 os << "\n\\end_float ";
143 // The beginning or end of a deeper (i.e. nested) area?
146 while (depth > dth) {
147 os << "\n\\begin_deeper ";
151 while (depth < dth) {
152 os << "\n\\end_deeper ";
158 // First write the layout
160 << textclasslist.NameOfLayout(params.textclass, layout)
163 // Maybe some vertical spaces.
164 if (added_space_top.kind() != VSpace::NONE)
165 os << "\\added_space_top "
166 << added_space_top.asLyXCommand() << " ";
167 if (added_space_bottom.kind() != VSpace::NONE)
168 os << "\\added_space_bottom "
169 << added_space_bottom.asLyXCommand() << " ";
171 // Maybe the paragraph has special spacing
172 spacing.writeFile(os, true);
174 // The labelwidth string used in lists.
175 if (!labelwidthstring.empty())
176 os << "\\labelwidthstring "
177 << labelwidthstring << '\n';
179 // Lines above or below?
183 os << "\\line_bottom ";
185 // Pagebreaks above or below?
187 os << "\\pagebreak_top ";
188 if (pagebreak_bottom)
189 os << "\\pagebreak_bottom ";
191 // Start of appendix?
192 if (start_of_appendix)
193 os << "\\start_of_appendix ";
200 if (align != LYX_ALIGN_LAYOUT) {
202 case LYX_ALIGN_LEFT: h = 1; break;
203 case LYX_ALIGN_RIGHT: h = 2; break;
204 case LYX_ALIGN_CENTER: h = 3; break;
205 default: h = 0; break;
207 os << "\\align " << string_align[h] << " ";
209 if (pextra_type != PEXTRA_NONE) {
210 os << "\\pextra_type " << pextra_type;
211 if (pextra_type == PEXTRA_MINIPAGE) {
212 os << " \\pextra_alignment "
215 os << " \\pextra_hfill "
217 if (pextra_start_minipage)
218 os << " \\pextra_start_minipage "
219 << pextra_start_minipage;
221 if (!pextra_width.empty()) {
222 os << " \\pextra_width "
223 << VSpace(pextra_width).asLyXCommand();
224 } else if (!pextra_widthp.empty()) {
225 os << " \\pextra_widthp "
231 // Dummy layout. This means that a footnote ended.
232 os << "\n\\end_float ";
233 footflag = LyXParagraph::NO_FOOTNOTE;
236 // It might be a table.
238 os << "\\LyXTable\n";
246 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
249 for (size_type i = 0; i < size(); ++i) {
255 // Write font changes
256 font2 = GetFontSettings(i);
257 if (font2 != font1) {
258 font2.lyxWriteChanges(font1, os);
267 Inset const * inset = GetInset(i);
269 if (inset->DirectWrite()) {
270 // international char, let it write
271 // code directly so it's shorter in
275 os << "\n\\begin_inset ";
277 os << "\n\\end_inset \n\n";
283 os << "\n\\newline \n";
287 os << "\n\\hfill \n";
291 os << "\n\\backslash \n";
295 if (i + 1 < size() && GetChar(i + 1) == ' ') {
302 if ((column > 70 && c == ' ')
307 // this check is to amend a bug. LyX sometimes
308 // inserts '\0' this could cause problems.
312 lyxerr << "ERROR (LyXParagraph::writeFile):"
313 " NULL char in structure." << endl;
319 // now write the next paragraph
321 next->writeFile(os, params, footflag, dth);
325 void LyXParagraph::validate(LaTeXFeatures & features) const
327 BufferParams const & params = features.bufferParams();
329 // this will be useful later
330 LyXLayout const & layout =
331 textclasslist.Style(params.textclass,
335 if (line_top || line_bottom)
336 features.lyxline = true;
337 if (!spacing.isDefault())
338 features.setspace = true;
341 features.layout[GetLayout()] = true;
344 Language const * doc_language = params.language_info;
346 for (FontList::const_iterator cit = fontlist.begin();
347 cit != fontlist.end(); ++cit) {
348 if ((*cit).font.noun() == LyXFont::ON) {
349 lyxerr[Debug::LATEX] << "font.noun: "
350 << (*cit).font.noun()
352 features.noun = true;
353 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
354 << (*cit).font.stateText()
357 switch ((*cit).font.color()) {
359 case LColor::inherit:
363 features.color = true;
364 lyxerr[Debug::LATEX] << "Color enabled. Font: "
365 << (*cit).font.stateText()
368 Language const * language = (*cit).font.language();
369 if (language != doc_language && language != default_language) {
370 features.UsedLanguages.insert(language);
371 lyxerr[Debug::LATEX] << "Found language "
372 << language->lang << endl;
377 for (InsetList::const_iterator cit = insetlist.begin();
378 cit != insetlist.end(); ++cit) {
380 (*cit).inset->Validate(features);
383 if (table && table->IsLongTable())
384 features.longtable = true;
385 if (pextra_type == PEXTRA_INDENT)
386 features.LyXParagraphIndent = true;
387 if (pextra_type == PEXTRA_FLOATFLT)
388 features.floatflt = true;
389 if (layout.needprotect
390 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
391 features.NeedLyXFootnoteCode = true;
392 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
393 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
394 features.NeedLyXMinipageIndent = true;
395 if (table && table->NeedRotating())
396 features.rotating = true;
397 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
398 features.algorithm = true;
402 // First few functions needed for cut and paste and paragraph breaking.
403 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
405 minibuffer_char = GetChar(pos);
406 minibuffer_font = GetFontSettings(pos);
407 minibuffer_inset = 0;
408 if (minibuffer_char == LyXParagraph::META_INSET) {
410 minibuffer_inset = GetInset(pos)->Clone();
412 minibuffer_inset = 0;
413 minibuffer_char = ' ';
414 // This reflects what GetInset() does (ARRae)
420 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
422 minibuffer_char = GetChar(pos);
423 minibuffer_font = GetFontSettings(pos);
424 minibuffer_inset = 0;
425 if (minibuffer_char == LyXParagraph::META_INSET) {
427 minibuffer_inset = GetInset(pos);
428 // This is a little hack since I want exactly
429 // the inset, not just a clone. Otherwise
430 // the inset would be deleted when calling Erase(pos)
432 InsetList::iterator it = lower_bound(insetlist.begin(),
435 if (it != insetlist.end() && (*it).pos == pos)
438 minibuffer_inset = 0;
439 minibuffer_char = ' ';
440 // This reflects what GetInset() does (ARRae)
445 // Erase(pos); now the caller is responsible for that.
449 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
451 if ((minibuffer_char == LyXParagraph::META_INSET) &&
452 !InsertInsetAllowed(minibuffer_inset))
454 InsertChar(pos, minibuffer_char);
455 SetFont(pos, minibuffer_font);
456 if (minibuffer_char == LyXParagraph::META_INSET)
457 InsertInset(pos, minibuffer_inset);
465 void LyXParagraph::Clear()
470 pagebreak_top = false;
471 pagebreak_bottom = false;
473 added_space_top = VSpace(VSpace::NONE);
474 added_space_bottom = VSpace(VSpace::NONE);
475 spacing.set(Spacing::Default);
477 align = LYX_ALIGN_LAYOUT;
481 pextra_type = PEXTRA_NONE;
482 pextra_width.clear();
483 pextra_widthp.clear();
484 pextra_alignment = MINIPAGE_ALIGN_TOP;
485 pextra_hfill = false;
486 pextra_start_minipage = false;
489 labelwidthstring.clear();
493 start_of_appendix = false;
497 // the destructor removes the new paragraph from the list
498 LyXParagraph::~LyXParagraph()
501 previous->next = next;
503 next->previous = previous;
505 for (InsetList::iterator it = insetlist.begin();
506 it != insetlist.end(); ++it) {
510 /* table stuff -- begin*/
512 /* table stuff -- end*/
517 //lyxerr << "LyXParagraph::paragraph_id = "
518 // << LyXParagraph::paragraph_id << endl;
522 void LyXParagraph::Erase(LyXParagraph::size_type pos)
524 // > because last is the next unused position, and you can
525 // use it if you want
527 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
528 NextAfterFootnote()->Erase(pos - text.size() - 1);
530 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
531 "position does not exist." << endl;
534 if (pos < size()) { // last is free for insertation, but should be empty
535 // if it is an inset, delete the inset entry
536 if (text[pos] == LyXParagraph::META_INSET) {
538 InsetList::iterator it = lower_bound(insetlist.begin(),
541 if (it != insetlist.end() && (*it).pos == pos) {
546 text.erase(text.begin() + pos);
547 // Erase entries in the tables.
548 for (FontList::iterator it = fontlist.begin();
549 it != fontlist.end(); ++it) {
550 if (pos >= (*it).pos && pos <= (*it).pos_end) {
551 if ((*it).pos == (*it).pos_end) {
552 // If it is a multi-character font
553 // entry, we just make it smaller
554 // (see update below), otherwise we
561 // Update all other entries.
562 for (FontList::iterator it = fontlist.begin();
563 it != fontlist.end(); ++it) {
566 if ((*it).pos_end >= pos)
570 // Update the inset table.
571 for (InsetList::iterator it = upper_bound(insetlist.begin(),
574 it != insetlist.end(); ++it)
577 lyxerr << "ERROR (LyXParagraph::Erase): "
578 "can't erase non-existant char." << endl;
583 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
585 // > because last is the next unused position, and you can
586 // use it if you want
589 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
590 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
593 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
594 "position does not exist." << endl;
597 text.insert(text.begin() + pos, c);
598 // Update the font table.
599 for (FontList::iterator it = fontlist.begin();
600 it != fontlist.end(); ++it) {
601 if ((*it).pos >= pos)
603 if ((*it).pos_end >= pos)
607 // Update the inset table.
608 for (InsetList::iterator it = lower_bound(insetlist.begin(),
611 it != insetlist.end(); ++it)
616 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
619 // > because last is the next unused position, and you can
620 // use it if you want
623 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
625 ->InsertInset(pos - text.size() - 1, inset);
627 lyxerr << "ERROR (LyXParagraph::InsertInset): "
628 "position does not exist: " << pos << endl;
631 if (text[pos] != LyXParagraph::META_INSET) {
632 lyxerr << "ERROR (LyXParagraph::InsertInset): "
633 "there is no LyXParagraph::META_INSET" << endl;
638 // Add a new entry in the inset table.
639 InsetList::iterator it = lower_bound(insetlist.begin(),
642 if (it != insetlist.end() && (*it).pos == pos)
643 lyxerr << "ERROR (LyXParagraph::InsertInset): "
644 "there is an inset in position: " << pos << endl;
646 insetlist.insert(it, InsetTable(pos,inset));
651 bool LyXParagraph::InsertInsetAllowed(Inset *inset)
654 printf("CODE:%d\n",inset->LyxCode());
655 return inset_owner->InsertInsetAllowed(inset);
660 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
664 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
665 return NextAfterFootnote()
666 ->GetInset(pos - text.size() - 1);
668 lyxerr << "ERROR (LyXParagraph::GetInset): "
669 "position does not exist: "
675 InsetList::iterator it = lower_bound(insetlist.begin(),
678 if (it != insetlist.end() && (*it).pos == pos)
681 lyxerr << "ERROR (LyXParagraph::GetInset): "
682 "Inset does not exist: " << pos << endl;
683 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
684 // Did this commenting out introduce a bug? So far I have not
685 // see any, please enlighten me. (Lgb)
686 // My guess is that since the inset does not exist, we might
687 // as well replace it with a space to prevent craches. (Asger)
692 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
696 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
697 return NextAfterFootnote()
698 ->GetInset(pos - text.size() - 1);
700 lyxerr << "ERROR (LyXParagraph::GetInset): "
701 "position does not exist: "
707 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
710 if (cit != insetlist.end() && (*cit).pos == pos)
713 lyxerr << "ERROR (LyXParagraph::GetInset): "
714 "Inset does not exist: " << pos << endl;
715 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
716 // Did this commenting out introduce a bug? So far I have not
717 // see any, please enlighten me. (Lgb)
718 // My guess is that since the inset does not exist, we might
719 // as well replace it with a space to prevent craches. (Asger)
724 // Gets uninstantiated font setting at position.
725 // Optimized after profiling. (Asger)
726 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
729 #ifdef SORTED_FONT_LIST
730 for (FontList::const_iterator cit = fontlist.begin();
731 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
732 if (pos >= (*cit).pos)
735 for (FontList::const_iterator cit = fontlist.begin();
736 cit != fontlist.end(); ++cit)
737 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
741 // > because last is the next unused position, and you can
742 // use it if you want
743 else if (pos > size()) {
745 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
746 return NextAfterFootnote()
747 ->GetFontSettings(pos - text.size() - 1);
749 // Why is it an error to ask for the font of a
750 // position that does not exist? Would it be
751 // enough for this to be enabled on debug?
752 // We want strict error checking, but it's ok to only
753 // have it when debugging. (Asger)
754 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
755 "position does not exist. "
756 << pos << " (" << static_cast<int>(pos)
759 } else if (pos > 0) {
760 return GetFontSettings(pos - 1);
761 } else // pos = size() = 0
762 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
764 return LyXFont(LyXFont::ALL_INHERIT);
767 // Gets uninstantiated font setting at position 0
768 LyXFont LyXParagraph::GetFirstFontSettings() const
771 #ifdef SORTED_FONT_LIST
772 if (!fontlist.empty() && fontlist.front().pos == 0)
773 return fontlist.front().font;
775 for (FontList::const_iterator cit = fontlist.begin();
776 cit != fontlist.end(); ++cit)
777 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
780 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
781 return NextAfterFootnote()->GetFirstFontSettings();
782 return LyXFont(LyXFont::ALL_INHERIT);
785 // Gets the fully instantiated font at a given position in a paragraph
786 // This is basically the same function as LyXText::GetFont() in text2.C.
787 // The difference is that this one is used for generating the LaTeX file,
788 // and thus cosmetic "improvements" are disallowed: This has to deliver
789 // the true picture of the buffer. (Asger)
790 // If position is -1, we get the layout font of the paragraph.
791 // If position is -2, we get the font of the manual label of the paragraph.
792 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
795 LyXLayout const & layout =
796 textclasslist.Style(current_view->buffer()->params.textclass,
798 LyXParagraph::size_type main_body = 0;
799 if (layout.labeltype == LABEL_MANUAL)
800 main_body = BeginningOfMainBody();
805 layoutfont = layout.labelfont;
807 layoutfont = layout.font;
808 tmpfont = GetFontSettings(pos);
809 tmpfont.realize(layoutfont);
811 // process layoutfont for pos == -1 and labelfont for pos < -1
813 tmpfont = layout.font;
815 tmpfont = layout.labelfont;
816 tmpfont.setLanguage(getParLanguage());
819 // check for environment font information
820 char par_depth = GetDepth();
821 LyXParagraph const * par = this;
822 while (par && par_depth && !tmpfont.resolved()) {
823 par = par->DepthHook(par_depth - 1);
825 tmpfont.realize(textclasslist.
826 Style(current_view->buffer()->params.textclass,
827 par->GetLayout()).font);
828 par_depth = par->GetDepth();
832 tmpfont.realize(textclasslist
833 .TextClass(current_view->buffer()->params.textclass)
839 /// Returns the height of the highest font in range
841 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
842 LyXParagraph::size_type endpos) const
844 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
845 for (FontList::const_iterator cit = fontlist.begin();
846 cit != fontlist.end(); ++cit) {
847 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
848 LyXFont::FONT_SIZE size = (*cit).font.size();
849 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
857 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
864 // > because last is the next unused position, and you can
865 // use it if you want
866 else if (pos > size()) {
867 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
868 return NextAfterFootnote()
869 ->GetChar(pos - text.size() - 1);
871 lyxerr << "ERROR (LyXParagraph::GetChar): "
872 "position does not exist."
873 << pos << " (" << static_cast<int>(pos)
875 // Assert(false); // This triggers sometimes...
880 // We should have a footnote environment.
881 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
882 // Notice that LyX does request the
883 // last char from time to time. (Asger)
884 //lyxerr << "ERROR (LyXParagraph::GetChar): "
885 // "expected footnote." << endl;
888 switch (next->footnotekind) {
889 case LyXParagraph::FOOTNOTE:
890 return LyXParagraph::META_FOOTNOTE;
891 case LyXParagraph::MARGIN:
892 return LyXParagraph::META_MARGIN;
893 case LyXParagraph::FIG:
894 case LyXParagraph::WIDE_FIG:
895 return LyXParagraph::META_FIG;
896 case LyXParagraph::TAB:
897 case LyXParagraph::WIDE_TAB:
898 return LyXParagraph::META_TAB;
899 case LyXParagraph::ALGORITHM:
900 return LyXParagraph::META_ALGORITHM;
902 return '\0'; // to shut up gcc
907 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
914 // > because last is the next unused position, and you can
915 // use it if you want
916 else if (pos > size()) {
917 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
918 return NextAfterFootnote()
919 ->GetChar(pos - text.size() - 1);
921 lyxerr << "ERROR (LyXParagraph::GetChar const): "
922 "position does not exist."
923 << pos << " (" << static_cast<int>(pos)
929 // We should have a footnote environment.
930 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
931 // Notice that LyX does request the
932 // last char from time to time. (Asger)
933 //lyxerr << "ERROR (LyXParagraph::GetChar): "
934 // "expected footnote." << endl;
937 switch (next->footnotekind) {
938 case LyXParagraph::FOOTNOTE:
939 return LyXParagraph::META_FOOTNOTE;
940 case LyXParagraph::MARGIN:
941 return LyXParagraph::META_MARGIN;
942 case LyXParagraph::FIG:
943 case LyXParagraph::WIDE_FIG:
944 return LyXParagraph::META_FIG;
945 case LyXParagraph::TAB:
946 case LyXParagraph::WIDE_TAB:
947 return LyXParagraph::META_TAB;
948 case LyXParagraph::ALGORITHM:
949 return LyXParagraph::META_ALGORITHM;
951 return '\0'; // to shut up gcc
956 // return an string of the current word, and the end of the word in lastpos.
957 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
961 // the current word is defined as starting at the first character
962 // from the immediate left of lastpospos which meets the definition
963 // of IsLetter(), continuing to the last character to the right
964 // of this meeting IsLetter.
970 // move back until we have a letter
972 //there's no real reason to have firstpos & lastpos as
973 //separate variables as this is written, but maybe someon
974 // will want to return firstpos in the future.
976 //since someone might have typed a punctuation first
977 int firstpos = lastpos;
979 while ((firstpos >= 0) && !IsLetter(firstpos))
982 // now find the beginning by looking for a nonletter
984 while ((firstpos>= 0) && IsLetter(firstpos))
987 // the above is now pointing to the preceeding non-letter
991 // so copy characters into theword until we get a nonletter
992 // note that this can easily exceed lastpos, wich means
993 // that if used in the middle of a word, the whole word
996 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1003 LyXParagraph::size_type LyXParagraph::Last() const
1005 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1006 return text.size() + NextAfterFootnote()->Last() + 1;
1007 // the 1 is the symbol
1014 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1016 // > because last is the next unused position, and you can
1017 // use it if you want
1020 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1021 return NextAfterFootnote()
1022 ->ParFromPos(pos - text.size() - 1);
1024 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1025 "position does not exist." << endl;
1032 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1034 // > because last is the next unused position, and you can
1035 // use it if you want
1038 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1039 return NextAfterFootnote()
1040 ->PositionInParFromPos(pos - text.size() - 1);
1043 "ERROR (LyXParagraph::PositionInParFromPos): "
1044 "position does not exist." << endl;
1052 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1053 LyXFont const & font)
1055 // > because last is the next unused position, and you can
1056 // use it if you want
1059 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1060 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1063 lyxerr << "ERROR (LyXParagraph::SetFont): "
1064 "position does not exist." << endl;
1068 LyXFont patternfont(LyXFont::ALL_INHERIT);
1070 // First, reduce font against layout/label font
1071 // Update: The SetCharFont() routine in text2.C already
1072 // reduces font, so we don't need to do that here. (Asger)
1073 // No need to simplify this because it will disappear
1074 // in a new kernel. (Asger)
1075 // Next search font table
1076 FontList::iterator tmp = fontlist.begin();
1077 for (; tmp != fontlist.end(); ++tmp) {
1078 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1082 if (tmp == fontlist.end()) { // !found
1083 // if we did not find a font entry, but if the font at hand
1084 // is the same as default, we just forget it
1085 if (font == patternfont) return;
1087 // ok, we did not find a font entry. But maybe there is exactly
1088 // the needed font ientry one position left
1089 FontList::iterator tmp2 = fontlist.begin();
1090 for (; tmp2 != fontlist.end(); ++tmp2) {
1091 if (pos - 1 >= (*tmp2).pos
1092 && pos - 1 <= (*tmp2).pos_end)
1095 if (tmp2 != fontlist.end()) {
1096 // ok there is one, maybe it is exactly
1098 if ((*tmp2).font == font) {
1099 // put the position under the font
1104 // Add a new entry in the
1105 // fontlist for the position
1109 ft.font = font; // or patternfont
1110 // It seems that using font instead of patternfont here
1111 // fixes all the problems. This also surfaces a "bug" in
1113 fontlist.insert(fontlist.begin(), ft);
1114 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1116 // more than one character
1117 if (pos == (*tmp).pos) {
1118 // maybe we should enlarge the left fonttable
1119 FontList::iterator tmp2 = fontlist.begin();
1120 for (; tmp2 != fontlist.end(); ++tmp2) {
1121 if (pos - 1 >= (*tmp2).pos
1122 && pos - 1 <= (*tmp2).pos_end)
1125 // Is there is one, and is it exactly
1127 if (tmp2 != fontlist.end() &&
1128 (*tmp2).font == font) {
1129 // Put the position under the font
1135 // Add a new entry in the
1136 // fontlist for the position
1139 ft.pos_end = (*tmp).pos_end;
1140 ft.font = (*tmp).font;
1141 (*tmp).pos_end = pos;
1143 fontlist.insert(fontlist.begin(), ft);
1144 } else if (pos == (*tmp).pos_end) {
1145 // Add a new entry in the
1146 // fontlist for the position
1148 ft.pos = (*tmp).pos;
1149 ft.pos_end = (*tmp).pos_end - 1;
1150 ft.font = (*tmp).font;
1151 (*tmp).pos = (*tmp).pos_end;
1153 fontlist.insert(fontlist.begin(), ft);
1155 // Add a new entry in the
1156 // fontlist for the position
1158 ft.pos = (*tmp).pos;
1159 ft.pos_end = pos - 1;
1160 ft.font = (*tmp).font;
1164 ft2.pos_end = (*tmp).pos_end;
1165 ft2.font = (*tmp).font;
1168 (*tmp).pos_end = pos;
1171 fontlist.insert(fontlist.begin(), ft);
1172 fontlist.insert(fontlist.begin(), ft2);
1180 // This function is able to hide closed footnotes.
1181 LyXParagraph * LyXParagraph::Next()
1183 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1184 LyXParagraph * tmp = next;
1186 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1188 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1189 return tmp->Next(); /* there can be more than one
1190 footnote in a logical
1193 return next; // This should never happen!
1199 LyXParagraph * LyXParagraph::NextAfterFootnote()
1201 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1202 LyXParagraph * tmp = next;
1203 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1205 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1206 return tmp; /* there can be more than one footnote
1207 in a logical paragraph */
1209 return next; // This should never happen!
1215 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1217 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1218 LyXParagraph * tmp = next;
1219 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1221 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1222 return tmp; /* there can be more than one footnote
1223 in a logical paragraph */
1225 return next; // This should never happen!
1231 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1234 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1236 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1237 tmp = tmp->previous;
1238 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1239 return tmp; /* there can be more than one footnote
1240 in a logical paragraph */
1242 return previous; // This should never happen!
1248 LyXParagraph * LyXParagraph::LastPhysicalPar()
1250 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1253 LyXParagraph * tmp = this;
1255 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1256 tmp = tmp->NextAfterFootnote();
1261 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1263 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1266 LyXParagraph const * tmp = this;
1268 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1269 tmp = tmp->NextAfterFootnote();
1274 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1278 LyXParagraph * tmppar = this;
1282 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1283 tmppar = tmppar->previous;
1292 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1296 LyXParagraph const * tmppar = this;
1300 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1301 tmppar = tmppar->previous;
1310 // This function is able to hide closed footnotes.
1311 LyXParagraph * LyXParagraph::Previous()
1313 LyXParagraph * tmp = previous;
1318 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1319 tmp = tmp->previous;
1321 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1322 tmp = tmp->previous;
1323 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1324 return tmp->next->Previous();
1333 // This function is able to hide closed footnotes.
1334 LyXParagraph const * LyXParagraph::Previous() const
1336 LyXParagraph * tmp = previous;
1341 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1342 tmp = tmp->previous;
1344 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1345 tmp = tmp->previous;
1346 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1347 return tmp->next->Previous();
1356 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1359 size_type i, j, pos_end, pos_first;
1360 // create a new paragraph
1361 LyXParagraph * par = ParFromPos(pos);
1362 LyXParagraph * firstpar = FirstPhysicalPar();
1364 LyXParagraph * tmp = new LyXParagraph(par);
1366 tmp->footnoteflag = footnoteflag;
1367 tmp->footnotekind = footnotekind;
1369 // this is an idea for a more userfriendly layout handling, I will
1370 // see what the users say
1372 // layout stays the same with latex-environments
1374 tmp->SetOnlyLayout(firstpar->layout);
1375 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1378 if (Last() > pos || !Last() || flag == 2) {
1379 tmp->SetOnlyLayout(firstpar->layout);
1380 tmp->align = firstpar->align;
1381 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1383 tmp->line_bottom = firstpar->line_bottom;
1384 firstpar->line_bottom = false;
1385 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1386 firstpar->pagebreak_bottom = false;
1387 tmp->added_space_bottom = firstpar->added_space_bottom;
1388 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1390 tmp->depth = firstpar->depth;
1391 tmp->noindent = firstpar->noindent;
1393 // copy everything behind the break-position
1394 // to the new paragraph
1396 while (ParFromPos(pos_first) != par)
1399 pos_end = pos_first + par->text.size() - 1;
1401 for (i = j = pos; i <= pos_end; ++i) {
1402 par->CutIntoMinibuffer(i - pos_first);
1403 if (tmp->InsertFromMinibuffer(j - pos))
1406 tmp->text.resize(tmp->text.size());
1407 for (i = pos_end; i >= pos; --i)
1408 par->Erase(i - pos_first);
1410 par->text.resize(par->text.size());
1413 // just an idea of me
1415 tmp->line_top = firstpar->line_top;
1416 tmp->pagebreak_top = firstpar->pagebreak_top;
1417 tmp->added_space_top = firstpar->added_space_top;
1418 tmp->bibkey = firstpar->bibkey;
1420 // layout stays the same with latex-environments
1422 firstpar->SetOnlyLayout(tmp->layout);
1423 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1424 firstpar->depth = tmp->depth;
1430 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1432 par = par->FirstPhysicalPar();
1433 footnoteflag = par->footnoteflag;
1434 footnotekind = par->footnotekind;
1436 layout = par->layout;
1437 align = par-> align;
1438 SetLabelWidthString(par->labelwidthstring);
1440 line_bottom = par->line_bottom;
1441 pagebreak_bottom = par->pagebreak_bottom;
1442 added_space_bottom = par->added_space_bottom;
1444 line_top = par->line_top;
1445 pagebreak_top = par->pagebreak_top;
1446 added_space_top = par->added_space_top;
1448 spacing = par->spacing;
1450 pextra_type = par->pextra_type;
1451 pextra_width = par->pextra_width;
1452 pextra_widthp = par->pextra_widthp;
1453 pextra_alignment = par->pextra_alignment;
1454 pextra_hfill = par->pextra_hfill;
1455 pextra_start_minipage = par->pextra_start_minipage;
1457 noindent = par->noindent;
1462 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1464 LyXParagraph * tmppar = this;
1467 && tmppar->previous->footnoteflag ==
1468 LyXParagraph::CLOSED_FOOTNOTE)
1469 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1470 tmppar = tmppar->previous;
1473 return this; // This should never happen!
1479 LyXParagraph * LyXParagraph::Clone() const
1481 // create a new paragraph
1482 LyXParagraph * result = new LyXParagraph;
1484 result->MakeSameLayout(this);
1486 // this is because of the dummy layout of the paragraphs that
1488 result->layout = layout;
1490 /* table stuff -- begin*/
1492 result->table = table->Clone();
1495 /* table stuff -- end*/
1497 result->inset_owner = inset_owner;
1500 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1503 // copy everything behind the break-position to the new paragraph
1505 result->text = text;
1506 result->fontlist = fontlist;
1507 result->insetlist = insetlist;
1508 for (InsetList::iterator it = result->insetlist.begin();
1509 it != result->insetlist.end(); ++it)
1510 (*it).inset = (*it).inset->Clone();
1515 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1517 par = par->FirstPhysicalPar();
1520 par->footnoteflag == footnoteflag &&
1521 par->footnotekind == footnotekind &&
1523 par->layout == layout &&
1525 par->align == align &&
1527 par->line_bottom == line_bottom &&
1528 par->pagebreak_bottom == pagebreak_bottom &&
1529 par->added_space_bottom == added_space_bottom &&
1531 par->line_top == line_top &&
1532 par->pagebreak_top == pagebreak_top &&
1533 par->added_space_top == added_space_top &&
1535 par->spacing == spacing &&
1537 par->pextra_type == pextra_type &&
1538 par->pextra_width == pextra_width &&
1539 par->pextra_widthp == pextra_widthp &&
1540 par->pextra_alignment == pextra_alignment &&
1541 par->pextra_hfill == pextra_hfill &&
1542 par->pextra_start_minipage == pextra_start_minipage &&
1544 par->table == table && // what means: NO TABLE AT ALL
1546 par->noindent == noindent &&
1547 par->depth == depth);
1551 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1553 // create a new paragraph
1554 LyXParagraph * par = ParFromPos(pos);
1556 LyXParagraph * tmp = new LyXParagraph(par);
1558 tmp->MakeSameLayout(par);
1560 // When can pos < Last()?
1561 // I guess pos == Last() is possible.
1563 // copy everything behind the break-position to the new
1565 size_type pos_first = 0;
1566 while (ParFromPos(pos_first) != par)
1568 size_type pos_end = pos_first + par->text.size() - 1;
1571 for (i = j = pos; i <= pos_end; ++i) {
1572 par->CutIntoMinibuffer(i - pos_first);
1573 if (tmp->InsertFromMinibuffer(j - pos))
1576 tmp->text.resize(tmp->text.size());
1577 for (size_type i = pos_end; i >= pos; --i)
1578 par->Erase(i - pos_first);
1580 par->text.resize(par->text.size());
1585 // Be carefull, this does not make any check at all.
1586 void LyXParagraph::PasteParagraph()
1588 // copy the next paragraph to this one
1589 LyXParagraph * the_next = Next();
1591 LyXParagraph * firstpar = FirstPhysicalPar();
1593 // first the DTP-stuff
1594 firstpar->line_bottom = the_next->line_bottom;
1595 firstpar->added_space_bottom = the_next->added_space_bottom;
1596 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1598 size_type pos_end = the_next->text.size() - 1;
1599 size_type pos_insert = Last();
1601 // ok, now copy the paragraph
1603 for (i = j = 0; i <= pos_end; ++i) {
1604 the_next->CutIntoMinibuffer(i);
1605 if (InsertFromMinibuffer(pos_insert + j))
1609 // delete the next paragraph
1614 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1616 LyXParagraph * par = ParFromPos(pos);
1618 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1619 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1625 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1627 LyXParagraph * par = ParFromPos(pos);
1629 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1630 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1635 int LyXParagraph::GetEndLabel() const
1637 LyXParagraph const * par = this;
1638 int par_depth = GetDepth();
1640 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1642 textclasslist.Style(current_view->buffer()->params.textclass,
1643 layout).endlabeltype;
1644 if (endlabeltype != END_LABEL_NO_LABEL) {
1645 LyXParagraph const * last = this;
1646 if( footnoteflag == NO_FOOTNOTE)
1647 last = LastPhysicalPar();
1648 else if (next->footnoteflag == NO_FOOTNOTE)
1649 return endlabeltype;
1651 if (!last || !last->next)
1652 return endlabeltype;
1654 int next_depth = last->next->GetDepth();
1655 if (par_depth > next_depth ||
1656 (par_depth == next_depth && layout != last->next->GetLayout() ))
1657 return endlabeltype;
1662 par = par->DepthHook(par_depth - 1);
1664 par_depth = par->GetDepth();
1666 return END_LABEL_NO_LABEL;
1670 LyXTextClass::size_type LyXParagraph::GetLayout() const
1672 return FirstPhysicalPar()->layout;
1676 char LyXParagraph::GetDepth() const
1678 return FirstPhysicalPar()->depth;
1682 char LyXParagraph::GetAlign() const
1684 return FirstPhysicalPar()->align;
1688 string LyXParagraph::GetLabelstring() const
1690 return FirstPhysicalPar()->labelstring;
1694 int LyXParagraph::GetFirstCounter(int i) const
1696 return FirstPhysicalPar()->counter_[i];
1700 // the next two functions are for the manual labels
1701 string LyXParagraph::GetLabelWidthString() const
1703 if (!FirstPhysicalPar()->labelwidthstring.empty())
1704 return FirstPhysicalPar()->labelwidthstring;
1706 return _("Senseless with this layout!");
1710 void LyXParagraph::SetLabelWidthString(string const & s)
1712 LyXParagraph * par = FirstPhysicalPar();
1714 par->labelwidthstring = s;
1718 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1720 LyXParagraph * par = FirstPhysicalPar();
1721 LyXParagraph * ppar = 0;
1722 LyXParagraph * npar = 0;
1724 par->layout = new_layout;
1725 /* table stuff -- begin*/
1728 /* table stuff -- end*/
1729 if (par->pextra_type == PEXTRA_NONE) {
1730 if (par->Previous()) {
1731 ppar = par->Previous()->FirstPhysicalPar();
1734 && (ppar->depth > par->depth))
1735 ppar = ppar->Previous()->FirstPhysicalPar();
1738 npar = par->Next()->NextAfterFootnote();
1741 && (npar->depth > par->depth))
1742 npar = npar->Next()->NextAfterFootnote();
1744 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1746 p1 = ppar->pextra_width,
1747 p2 = ppar->pextra_widthp;
1748 ppar->SetPExtraType(ppar->pextra_type,
1749 p1.c_str(), p2.c_str());
1751 if ((par->pextra_type == PEXTRA_NONE) &&
1752 npar && (npar->pextra_type != PEXTRA_NONE)) {
1754 p1 = npar->pextra_width,
1755 p2 = npar->pextra_widthp;
1756 npar->SetPExtraType(npar->pextra_type,
1757 p1.c_str(), p2.c_str());
1763 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1766 * par = FirstPhysicalPar(),
1770 par->layout = new_layout;
1771 par->labelwidthstring.clear();
1772 par->align = LYX_ALIGN_LAYOUT;
1773 par->added_space_top = VSpace(VSpace::NONE);
1774 par->added_space_bottom = VSpace(VSpace::NONE);
1775 par->spacing.set(Spacing::Default);
1777 /* table stuff -- begin*/
1780 /* table stuff -- end*/
1781 if (par->pextra_type == PEXTRA_NONE) {
1782 if (par->Previous()) {
1783 ppar = par->Previous()->FirstPhysicalPar();
1786 && (ppar->depth > par->depth))
1787 ppar = ppar->Previous()->FirstPhysicalPar();
1790 npar = par->Next()->NextAfterFootnote();
1793 && (npar->depth > par->depth))
1794 npar = npar->Next()->NextAfterFootnote();
1796 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1798 p1 = ppar->pextra_width,
1799 p2 = ppar->pextra_widthp;
1800 ppar->SetPExtraType(ppar->pextra_type,
1801 p1.c_str(), p2.c_str());
1803 if ((par->pextra_type == PEXTRA_NONE) &&
1804 npar && (npar->pextra_type != PEXTRA_NONE)) {
1806 p1 = npar->pextra_width,
1807 p2 = npar->pextra_widthp;
1808 npar->SetPExtraType(npar->pextra_type,
1809 p1.c_str(), p2.c_str());
1815 // if the layout of a paragraph contains a manual label, the beginning of the
1816 // main body is the beginning of the second word. This is what the par-
1817 // function returns. If the layout does not contain a label, the main
1818 // body always starts with position 0. This differentiation is necessary,
1819 // because there cannot be a newline or a blank <= the beginning of the
1820 // main body in TeX.
1822 int LyXParagraph::BeginningOfMainBody() const
1824 if (FirstPhysicalPar() != this)
1827 // Unroll the first two cycles of the loop
1828 // and remember the previous character to
1829 // remove unnecessary GetChar() calls
1832 && GetChar(i) != LyXParagraph::META_NEWLINE
1835 char previous_char = 0, temp = 0;
1837 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1838 // Yes, this ^ is supposed to be "= " not "=="
1841 && previous_char != ' '
1842 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1844 previous_char = temp;
1849 if (i == 0 && i == size() &&
1850 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1851 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1852 ++i; /* the cursor should not jump
1853 * to the main body if there
1859 LyXParagraph * LyXParagraph::DepthHook(int deth)
1861 LyXParagraph * newpar = this;
1866 newpar = newpar->FirstPhysicalPar()->Previous();
1867 } while (newpar && newpar->GetDepth() > deth
1868 && newpar->footnoteflag == footnoteflag);
1871 if (Previous() || GetDepth())
1872 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1876 return newpar->FirstPhysicalPar();
1880 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1882 LyXParagraph const * newpar = this;
1887 newpar = newpar->FirstPhysicalPar()->Previous();
1888 } while (newpar && newpar->GetDepth() > deth
1889 && newpar->footnoteflag == footnoteflag);
1892 if (Previous() || GetDepth())
1893 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1897 return newpar->FirstPhysicalPar();
1901 int LyXParagraph::AutoDeleteInsets()
1904 InsetList::size_type index = 0;
1905 while (index < insetlist.size()) {
1906 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1907 Erase(insetlist[index].pos);
1908 // Erase() calls to insetlist.erase(&insetlist[index])
1909 // so index shouldn't be increased.
1918 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1920 InsetList::iterator it = lower_bound(insetlist.begin(),
1923 if (it != insetlist.end()) {
1931 // returns -1 if inset not found
1932 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1935 // We could use lower_bound here too, we just need to add
1936 // the approp. operator() to matchIT (and change the name
1937 // of that struct). Code would then be:
1938 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1940 // inset, matchIT());
1941 // if ((*cit).inset == inset) {
1942 // return (*cit).pos;
1944 for (InsetList::const_iterator cit = insetlist.begin();
1945 cit != insetlist.end(); ++cit) {
1946 if ((*cit).inset == inset) {
1950 // Think about footnotes.
1951 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1952 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1954 NextAfterFootnote()->GetPositionOfInset(inset);
1956 return text.size() + 1 + further;
1962 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1964 TexRow & foot_texrow,
1967 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1968 LyXLayout const & style =
1969 textclasslist.Style(current_view->buffer()->params.textclass,
1972 bool further_blank_line = false;
1974 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1976 if (start_of_appendix) {
1977 os << "\\appendix\n";
1981 if (!spacing.isDefault()
1982 && (!Previous() || !Previous()->HasSameLayout(this))) {
1983 os << spacing.writeEnvirBegin() << "\n";
1987 if (tex_code_break_column && style.isCommand()){
1992 if (pagebreak_top) {
1994 further_blank_line = true;
1996 if (added_space_top.kind() != VSpace::NONE) {
1997 os << added_space_top.asLatexCommand(current_view->buffer()->params);
1998 further_blank_line = true;
2002 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2003 << "\\vspace{-1\\parskip}";
2004 further_blank_line = true;
2007 if (further_blank_line){
2012 Language const * language = getParLanguage();
2013 Language const * doc_language = current_view->buffer()->params.language_info;
2014 if (language != doc_language) {
2015 os << subst(lyxrc.language_command_begin, "$$lang",
2021 switch (style.latextype) {
2024 << style.latexname()
2025 << style.latexparam();
2027 case LATEX_ITEM_ENVIRONMENT:
2029 bibkey->Latex(os, false, false);
2033 case LATEX_LIST_ENVIRONMENT:
2040 bool need_par = SimpleTeXOnePar(os, texrow);
2042 // Spit out footnotes
2043 LyXParagraph * par = next;
2044 if (lyxrc.rtl_support) {
2045 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2046 && next->footnoteflag != footnoteflag) {
2047 LyXParagraph * p = 0;
2048 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2049 if ( (p = NextAfterFootnote()) != 0 &&
2050 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2051 is_rtl = GetFontSettings(0).isRightToLeft();
2053 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2054 par->footnoteflag != footnoteflag) {
2055 par = par->TeXFootnote(os, texrow, foot,
2056 foot_texrow, foot_count,
2058 par->SimpleTeXOnePar(os, texrow);
2059 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2061 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2062 (p = par->NextAfterFootnote()) != 0 &&
2063 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2064 is_rtl = GetFontSettings(0).isRightToLeft();
2069 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2070 && par->footnoteflag != footnoteflag) {
2071 par = par->TeXFootnote(os, texrow,
2072 foot, foot_texrow, foot_count,
2074 par->SimpleTeXOnePar(os, texrow);
2079 // Make sure that \\par is done with the font of the last
2080 // character if this has another size as the default.
2081 // This is necessary because LaTeX (and LyX on the screen)
2082 // calculates the space between the baselines according
2083 // to this font. (Matthias)
2084 LyXFont font = getFont(Last() - 1);
2086 if (style.resfont.size() != font.size()) {
2092 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2093 GetLayout()).isCommand()){
2094 if (style.resfont.size() != font.size()) {
2100 } else if (style.resfont.size() != font.size()){
2101 os << "{\\" << font.latexSize() << " \\par}";
2104 if (language != doc_language) {
2106 << subst(lyxrc.language_command_end, "$$lang",
2107 doc_language->lang);
2110 switch (style.latextype) {
2111 case LATEX_ITEM_ENVIRONMENT:
2112 case LATEX_LIST_ENVIRONMENT:
2113 if (par && (depth < par->depth)) {
2118 case LATEX_ENVIRONMENT:
2119 // if its the last paragraph of the current environment
2120 // skip it otherwise fall through
2122 && (par->layout != layout
2123 || par->depth != depth
2124 || par->pextra_type != pextra_type))
2127 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2128 && footnotekind != LyXParagraph::FOOTNOTE
2129 && footnotekind != LyXParagraph::MARGIN
2133 // don't insert this if we would be adding it
2134 // before or after a table in a float. This
2135 // little trick is needed in order to allow
2136 // use of tables in \subfigures or \subtables.
2142 further_blank_line = false;
2144 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2145 further_blank_line = true;
2148 if (added_space_bottom.kind() != VSpace::NONE) {
2149 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2150 further_blank_line = true;
2153 if (pagebreak_bottom) {
2155 further_blank_line = true;
2158 if (further_blank_line){
2163 if (!spacing.isDefault()
2164 && (!par || !par->HasSameLayout(this))) {
2165 os << spacing.writeEnvirEnd() << "\n";
2169 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2170 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2175 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2180 // This one spits out the text of the paragraph
2181 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2183 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2186 return SimpleTeXOneTablePar(os, texrow);
2188 bool return_value = false;
2190 LyXLayout const & style =
2191 textclasslist.Style(current_view->buffer()->params.textclass,
2193 LyXFont basefont, last_font;
2195 // Maybe we have to create a optional argument.
2196 size_type main_body;
2197 if (style.labeltype != LABEL_MANUAL)
2200 main_body = BeginningOfMainBody();
2202 if (main_body > 0) {
2204 basefont = getFont(-2); // Get label font
2206 basefont = getFont(-1); // Get layout font
2214 if (style.isCommand()) {
2217 } else if (align != LYX_ALIGN_LAYOUT) {
2220 return_value = true;
2224 // Which font is currently active?
2225 LyXFont running_font(basefont);
2226 // Do we have an open font change?
2227 bool open_font = false;
2229 texrow.start(this, 0);
2231 for (size_type i = 0; i < size(); ++i) {
2233 // First char in paragraph or after label?
2234 if (i == main_body && !IsDummy()) {
2235 if (main_body > 0) {
2237 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2240 basefont = getFont(-1); // Now use the layout font
2241 running_font = basefont;
2245 if (style.isCommand()) {
2248 } else if (align != LYX_ALIGN_LAYOUT) {
2251 return_value = true;
2255 os << "\\noindent ";
2259 case LYX_ALIGN_NONE:
2260 case LYX_ALIGN_BLOCK:
2261 case LYX_ALIGN_LAYOUT:
2262 case LYX_ALIGN_SPECIAL:
2264 case LYX_ALIGN_LEFT:
2265 if (getParLanguage()->lang != "hebrew") {
2266 os << "\\raggedright ";
2269 os << "\\raggedleft ";
2273 case LYX_ALIGN_RIGHT:
2274 if (getParLanguage()->lang != "hebrew") {
2275 os << "\\raggedleft ";
2278 os << "\\raggedright ";
2282 case LYX_ALIGN_CENTER:
2283 os << "\\centering ";
2291 // Fully instantiated font
2292 LyXFont font = getFont(i);
2293 LyXParagraph * p = 0;
2294 if (i == 0 && previous &&
2295 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2296 (p = PreviousBeforeFootnote()) != 0)
2297 last_font = p->getFont(p->size()-1);
2299 last_font = running_font;
2301 // Spaces at end of font change are simulated to be
2302 // outside font change, i.e. we write "\textXX{text} "
2303 // rather than "\textXX{text }". (Asger)
2304 if (open_font && c == ' ' && i <= size() - 2
2305 && !getFont(i+1).equalExceptLatex(running_font)
2306 && !getFont(i+1).equalExceptLatex(font)) {
2307 font = getFont(i + 1);
2309 // We end font definition before blanks
2310 if (!font.equalExceptLatex(running_font) && open_font) {
2311 column += running_font.latexWriteEndChanges(os,
2313 (i == main_body-1) ? basefont : font);
2314 running_font = basefont;
2318 // Blanks are printed before start of fontswitch
2320 // Do not print the separation of the optional argument
2321 if (i != main_body - 1) {
2322 SimpleTeXBlanks(os, texrow, i,
2323 column, font, style);
2327 // Do we need to change font?
2328 if (!font.equalExceptLatex(running_font)
2329 && i != main_body-1) {
2330 column += font.latexWriteStartChanges(os, basefont,
2332 running_font = font;
2336 if (c == LyXParagraph::META_NEWLINE) {
2337 // newlines are handled differently here than
2338 // the default in SimpleTeXSpecialChars().
2339 if (!style.newline_allowed
2340 || font.latex() == LyXFont::ON) {
2344 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2347 basefont = getFont(-1);
2348 running_font = basefont;
2349 if (font.family() ==
2350 LyXFont::TYPEWRITER_FAMILY) {
2356 texrow.start(this, i + 1);
2359 SimpleTeXSpecialChars(os, texrow,
2360 font, running_font, basefont,
2361 open_font, style, i, column, c);
2365 // If we have an open font definition, we have to close it
2367 LyXParagraph * p = 0;
2368 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2369 && (p = NextAfterFootnote()) != 0)
2370 running_font.latexWriteEndChanges(os, basefont,
2373 running_font.latexWriteEndChanges(os, basefont, basefont);
2376 // Needed if there is an optional argument but no contents.
2377 if (main_body > 0 && main_body == size()) {
2379 return_value = false;
2382 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2383 return return_value;
2387 // This one spits out the text of a table paragraph
2388 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2390 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2392 bool return_value = false;
2394 LyXLayout const & style =
2395 textclasslist.Style(current_view->buffer()->params.textclass,
2399 if (!IsDummy()) { // it is dummy if it is in a float!!!
2400 if (style.isCommand()) {
2403 } else if (align != LYX_ALIGN_LAYOUT) {
2406 return_value = true;
2409 os << "\\noindent ";
2413 case LYX_ALIGN_NONE:
2414 case LYX_ALIGN_BLOCK:
2415 case LYX_ALIGN_LAYOUT:
2416 case LYX_ALIGN_SPECIAL: break;
2417 case LYX_ALIGN_LEFT:
2418 os << "\\raggedright ";
2421 case LYX_ALIGN_RIGHT:
2422 os << "\\raggedleft ";
2425 case LYX_ALIGN_CENTER:
2426 os << "\\centering ";
2432 LyXFont basefont = getFont(-1); // Get layout font
2433 // Which font is currently active?
2434 LyXFont running_font = basefont;
2436 // Do we have an open font change?
2437 bool open_font = false;
2438 int current_cell_number = -1;
2439 int tmp = table->TexEndOfCell(os, current_cell_number);
2440 for (; tmp > 0 ; --tmp)
2443 texrow.start(this, 0);
2445 bool is_rtl = getParLanguage()->RightToLeft;
2446 bool first_in_cell = true;
2448 for (size_type i = 0; i < size(); ++i) {
2449 char c = GetChar(i);
2450 if (table->IsContRow(current_cell_number + 1)) {
2451 if (c == LyXParagraph::META_NEWLINE)
2452 ++current_cell_number;
2457 if (first_in_cell && is_rtl) {
2460 first_in_cell = false;
2463 // Fully instantiated font
2464 LyXFont font = getFont(i);
2465 last_font = running_font;
2467 // Spaces at end of font change are simulated to be
2468 // outside font change.
2469 // i.e. we write "\textXX{text} " rather than
2470 // "\textXX{text }". (Asger)
2471 if (open_font && c == ' ' && i <= size() - 2
2472 && getFont(i + 1) != running_font
2473 && getFont(i + 1) != font) {
2474 font = getFont(i + 1);
2477 // We end font definition before blanks
2478 if (font != running_font && open_font) {
2479 column += running_font.latexWriteEndChanges(os,
2482 running_font = basefont;
2485 // Blanks are printed before start of fontswitch
2487 SimpleTeXBlanks(os, texrow, i, column, font, style);
2489 // Do we need to change font?
2490 if (font != running_font) {
2491 column += font.latexWriteStartChanges(os, basefont,
2493 running_font = font;
2496 // Do we need to turn on LaTeX mode?
2497 if (font.latex() != running_font.latex()) {
2498 if (font.latex() == LyXFont::ON
2499 && style.needprotect) {
2504 if (c == LyXParagraph::META_NEWLINE) {
2505 // special case for inside a table
2506 // different from default case in
2507 // SimpleTeXSpecialChars()
2509 column += running_font
2510 .latexWriteEndChanges(os, basefont,
2514 basefont = getFont(-1);
2515 running_font = basefont;
2516 ++current_cell_number;
2517 if (table->CellHasContRow(current_cell_number) >= 0) {
2518 TeXContTableRows(os, i + 1,
2519 current_cell_number,
2522 if (is_rtl && !first_in_cell) {
2524 first_in_cell = true;
2527 // if this cell follow only ContRows till end don't
2528 // put the EndOfCell because it is put after the
2530 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2531 --current_cell_number;
2534 int tmp = table->TexEndOfCell(os,
2535 current_cell_number);
2538 } else if (tmp < 0) {
2544 texrow.start(this, i + 1);
2546 SimpleTeXSpecialChars(os, texrow,
2547 font, running_font, basefont,
2548 open_font, style, i, column, c);
2552 // If we have an open font definition, we have to close it
2554 running_font.latexWriteEndChanges(os, basefont, basefont);
2556 ++current_cell_number;
2557 if (is_rtl && !first_in_cell)
2559 tmp = table->TexEndOfCell(os, current_cell_number);
2560 for (; tmp > 0; --tmp)
2562 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2563 return return_value;
2567 // This one spits out the text off ContRows in tables
2568 bool LyXParagraph::TeXContTableRows(ostream & os,
2569 LyXParagraph::size_type i,
2570 int current_cell_number,
2571 int & column, TexRow & texrow)
2573 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2579 bool return_value = false;
2580 LyXLayout const & style =
2581 textclasslist.Style(current_view->buffer()->params.textclass,
2583 LyXFont basefont = getFont(-1); // Get layout font
2585 // Which font is currently active?
2586 LyXFont running_font = basefont;
2587 // Do we have an open font change?
2588 bool open_font = false;
2590 size_type lastpos = i;
2591 int cell = table->CellHasContRow(current_cell_number);
2592 ++current_cell_number;
2594 // first find the right position
2596 for (; (i < size()) && (current_cell_number<cell); ++i) {
2598 if (c == LyXParagraph::META_NEWLINE)
2599 ++current_cell_number;
2603 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2607 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2612 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2616 // Fully instantiated font
2617 LyXFont font = getFont(i);
2618 last_font = running_font;
2620 // Spaces at end of font change are simulated to
2621 // be outside font change. i.e. we write
2622 // "\textXX{text} " rather than "\textXX{text }".
2624 if (open_font && c == ' ' && i <= size() - 2
2625 && getFont(i + 1) != running_font
2626 && getFont(i + 1) != font) {
2627 font = getFont(i + 1);
2630 // We end font definition before blanks
2631 if (font != running_font && open_font) {
2632 column += running_font.latexWriteEndChanges(os, basefont, font);
2633 running_font = basefont;
2636 // Blanks are printed before start of fontswitch
2638 SimpleTeXBlanks(os, texrow, i,
2639 column, font, style);
2641 // Do we need to change font?
2642 if (font != running_font) {
2644 font.latexWriteStartChanges(os,
2647 running_font = font;
2650 // Do we need to turn on LaTeX mode?
2651 if (font.latex() != running_font.latex()) {
2652 if (font.latex() == LyXFont::ON
2653 && style.needprotect) {
2658 SimpleTeXSpecialChars(os, texrow, font,
2659 running_font, basefont,
2660 open_font, style, i, column, c);
2662 // If we have an open font definition, we have to close it
2664 running_font.latexWriteEndChanges(os, basefont,
2668 basefont = getFont(-1);
2669 running_font = basefont;
2670 cell = table->CellHasContRow(current_cell_number);
2672 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2673 return return_value;
2677 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2679 bool retval = false;
2681 case LyXParagraph::META_HFILL:
2682 sgml_string.clear();
2684 case LyXParagraph::META_NEWLINE:
2688 sgml_string = "&";
2691 sgml_string = "<";
2694 sgml_string = ">";
2697 sgml_string = "$";
2700 sgml_string = "#";
2703 sgml_string = "%";
2706 sgml_string = "[";
2709 sgml_string = "]";
2712 sgml_string = "{";
2715 sgml_string = "}";
2718 sgml_string = "˜";
2721 sgml_string = """;
2724 sgml_string = "\";
2730 case '\0': // Ignore :-)
2731 sgml_string.clear();
2741 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2742 int & desc_on, int depth)
2745 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2747 LyXFont font1, font2;
2750 size_type main_body;
2751 bool emph_flag = false;
2753 LyXLayout const & style =
2754 textclasslist.Style(current_view->buffer()->params.textclass,
2757 if (style.labeltype != LABEL_MANUAL)
2760 main_body = BeginningOfMainBody();
2762 // Gets paragraph main font.
2764 font1 = style.labelfont;
2768 int char_line_count = depth;
2769 os << newlineAndDepth(depth);
2770 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2771 os << "<INFORMALTABLE>"
2772 << newlineAndDepth(++depth);
2774 int current_cell_number = -1;
2775 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2777 // Parsing main loop.
2778 for (size_type i = 0; i < size(); ++i) {
2780 if (table->IsContRow(current_cell_number+1)) {
2781 if (c == LyXParagraph::META_NEWLINE)
2782 ++current_cell_number;
2787 // Fully instantiated font
2790 // Handle <emphasis> tag.
2791 if (font1.emph() != font2.emph() && i) {
2792 if (font2.emph() == LyXFont::ON) {
2795 } else if (emph_flag) {
2796 os << "</emphasis>";
2800 if (c == LyXParagraph::META_NEWLINE) {
2801 // We have only to control for emphasis open here!
2803 os << "</emphasis>";
2806 font1 = font2 = getFont(-1);
2807 ++current_cell_number;
2808 if (table->CellHasContRow(current_cell_number) >= 0) {
2809 DocBookContTableRows(os, extra, desc_on, i + 1,
2810 current_cell_number,
2813 // if this cell follow only ContRows till end don't
2814 // put the EndOfCell because it is put after the
2816 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2817 --current_cell_number;
2820 tmp = table->DocBookEndOfCell(os,
2821 current_cell_number,
2826 } else if (c == LyXParagraph::META_INSET) {
2827 inset = GetInset(i);
2829 std::ostringstream ost;
2830 inset->DocBook(ost);
2831 string tmp_out = ost.str().c_str();
2834 inset->DocBook(ost);
2836 char * ctmp = ost.str();
2837 string tmp_out(ctmp);
2841 // This code needs some explanation:
2842 // Two insets are treated specially
2843 // label if it is the first element in a
2844 // command paragraph
2846 // graphics inside tables or figure floats
2848 // title (the equivalente in latex for this
2850 // and title should come first
2853 if(desc_on != 3 || i != 0) {
2854 if(tmp_out[0] == '@') {
2856 extra += frontStrip(tmp_out,
2859 os << frontStrip(tmp_out,
2864 } else if (font2.latex() == LyXFont::ON) {
2865 // "TeX"-Mode on == > SGML-Mode on.
2871 if (linuxDocConvertChar(c, sgml_string)
2872 && !style.free_spacing) {
2873 // in freespacing mode, spaces are
2874 // non-breaking characters
2879 << "</term><listitem><para>";
2891 // Needed if there is an optional argument but no contents.
2892 if (main_body > 0 && main_body == size()) {
2897 os << "</emphasis>";
2900 ++current_cell_number;
2901 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2902 // Resets description flag correctly.
2905 // <term> not closed...
2909 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2910 os << "</INFORMALTABLE>";
2912 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2917 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2919 LyXParagraph::size_type i,
2920 int current_cell_number, int &column)
2925 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2930 //string emph = "emphasis";
2931 bool emph_flag = false;
2932 int char_line_count = 0;
2934 LyXLayout const & style =
2935 textclasslist.Style(current_view->buffer()->params.textclass,
2938 size_type main_body;
2939 if (style.labeltype != LABEL_MANUAL)
2942 main_body = BeginningOfMainBody();
2944 // Gets paragraph main font.
2947 font1 = style.labelfont;
2951 size_type lastpos = i;
2952 int cell = table->CellHasContRow(current_cell_number);
2953 ++current_cell_number;
2955 // first find the right position
2957 for (; i < size() && current_cell_number < cell; ++i) {
2959 if (c == LyXParagraph::META_NEWLINE)
2960 ++current_cell_number;
2964 // I don't know how to handle this so I comment it
2965 // for the moment (Jug)
2966 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2967 // file += " \\\\\n";
2970 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2975 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2979 // Fully instantiated font
2982 // Handle <emphasis> tag.
2983 if (font1.emph() != font2.emph() && i) {
2984 if (font2.emph() == LyXFont::ON) {
2987 } else if (emph_flag) {
2988 os << "</emphasis>";
2992 if (c == LyXParagraph::META_INSET) {
2993 inset = GetInset(i);
2995 std::ostringstream ost;
2996 inset->DocBook(ost);
2997 string tmp_out = ost.str().c_str();
3000 inset->DocBook(ost);
3002 char * ctmp = ost.str();
3003 string tmp_out(ctmp);
3007 // This code needs some explanation:
3008 // Two insets are treated specially
3009 // label if it is the first element in a
3010 // command paragraph
3012 // graphics inside tables or figure floats
3013 // can't go on title (the equivalente in
3014 // latex for this case is caption and title
3015 // should come first
3018 if(desc_on != 3 || i != 0) {
3019 if(tmp_out[0] == '@') {
3021 extra += frontStrip(tmp_out, '@');
3023 os << frontStrip(tmp_out, '@');
3027 } else if (font2.latex() == LyXFont::ON) {
3028 // "TeX"-Mode on == > SGML-Mode on.
3034 if (linuxDocConvertChar(c, sgml_string)
3035 && !style.free_spacing) {
3036 // in freespacing mode, spaces are
3037 // non-breaking characters
3042 << "</term><listitem><para>";
3052 // we have only to control for emphasis open here!
3054 os << "</emphasis>";
3057 font1 = font2 = getFont(-1);
3058 cell = table->CellHasContRow(current_cell_number);
3060 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3064 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3065 LyXParagraph::size_type const i,
3066 int & column, LyXFont const & font,
3067 LyXLayout const & style)
3069 if (column > tex_code_break_column
3071 && GetChar(i - 1) != ' '
3073 // In LaTeX mode, we don't want to
3074 // break lines since some commands
3076 && ! (font.latex() == LyXFont::ON)
3077 // same in FreeSpacing mode
3078 && !style.free_spacing
3079 // In typewriter mode, we want to avoid
3080 // ! . ? : at the end of a line
3081 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3082 && (GetChar(i-1) == '.'
3083 || GetChar(i-1) == '?'
3084 || GetChar(i-1) == ':'
3085 || GetChar(i-1) == '!'))) {
3086 if (tex_code_break_column == 0) {
3087 // in batchmode we need LaTeX to still
3088 // see it as a space not as an extra '\n'
3094 texrow.start(this, i + 1);
3096 } else if (font.latex() == LyXFont::OFF) {
3097 if (style.free_spacing) {
3106 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3108 LyXFont & running_font,
3111 LyXLayout const & style,
3112 LyXParagraph::size_type & i,
3113 int & column, char const c)
3115 // Two major modes: LaTeX or plain
3116 // Handle here those cases common to both modes
3117 // and then split to handle the two modes separately.
3119 case LyXParagraph::META_INSET: {
3120 Inset * inset = GetInset(i);
3123 int len = os.tellp();
3124 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3125 || inset->LyxCode() == Inset::MATH_CODE
3126 || inset->LyxCode() == Inset::URL_CODE)
3127 && running_font.isRightToLeft()) {
3130 } else if (inset->LyxCode() == Inset::NUMBER_CODE
3131 && running_font.isRightToLeft()) {
3136 int tmp = inset->Latex(os, style.isCommand(),
3137 style.free_spacing);
3140 if (inset->LyxCode() == Inset::NUMBER_CODE)
3148 column += os.tellp() - len;
3157 case LyXParagraph::META_NEWLINE:
3159 column += running_font.latexWriteEndChanges(os,
3164 basefont = getFont(-1);
3165 running_font = basefont;
3168 case LyXParagraph::META_HFILL:
3174 // And now for the special cases within each mode
3175 // Are we in LaTeX mode?
3176 if (font.latex() == LyXFont::ON) {
3177 // at present we only have one option
3178 // but I'll leave it as a switch statement
3179 // so its simpler to extend. (ARRae)
3182 // make sure that we will not print
3183 // error generating chars to the tex
3184 // file. This test would not be needed
3185 // if it were done in the buffer
3193 // Plain mode (i.e. not LaTeX)
3196 os << "\\textbackslash{}";
3200 case '°': case '±': case '²': case '³':
3201 case '×': case '÷': case '¹': case 'ª':
3202 case 'º': case '¬': case 'µ':
3203 if (current_view->buffer()->params.inputenc == "latin1") {
3204 os << "\\ensuremath{"
3213 case '|': case '<': case '>':
3214 // In T1 encoding, these characters exist
3215 if (lyxrc.fontenc == "T1") {
3217 //... but we should avoid ligatures
3218 if ((c == '>' || c == '<')
3220 && GetChar(i + 1) == c){
3221 os << "\\textcompwordmark{}";
3226 // Typewriter font also has them
3227 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3231 // Otherwise, we use what LaTeX
3235 os << "\\textless{}";
3239 os << "\\textgreater{}";
3243 os << "\\textbar{}";
3249 case '-': // "--" in Typewriter mode -> "-{}-"
3251 && GetChar(i + 1) == '-'
3252 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3261 os << "\\char`\\\"{}";
3266 if (current_view->buffer()->params.inputenc == "default") {
3275 case '%': case '#': case '{':
3282 os << "\\textasciitilde{}";
3287 os << "\\textasciicircum{}";
3291 case '*': case '[': case ']':
3292 // avoid being mistaken for optional arguments
3293 os << '{' << c << '}';
3298 // Blanks are printed before font switching.
3299 // Sure? I am not! (try nice-latex)
3300 // I am sure it's correct. LyX might be smarter
3301 // in the future, but for now, nothing wrong is
3306 /* idea for labels --- begin*/
3310 && font.family() != LyXFont::TYPEWRITER_FAMILY
3311 && GetChar(i + 1) == 'y'
3312 && GetChar(i + 2) == 'X') {
3320 && font.family() != LyXFont::TYPEWRITER_FAMILY
3321 && GetChar(i + 1) == 'e'
3322 && GetChar(i + 2) == 'X') {
3327 // Check for "LaTeX2e"
3330 && font.family() != LyXFont::TYPEWRITER_FAMILY
3331 && GetChar(i + 1) == 'a'
3332 && GetChar(i + 2) == 'T'
3333 && GetChar(i + 3) == 'e'
3334 && GetChar(i + 4) == 'X'
3335 && GetChar(i + 5) == '2'
3336 && GetChar(i + 6) == 'e') {
3341 // Check for "LaTeX"
3344 && font.family() != LyXFont::TYPEWRITER_FAMILY
3345 && GetChar(i + 1) == 'a'
3346 && GetChar(i + 2) == 'T'
3347 && GetChar(i + 3) == 'e'
3348 && GetChar(i + 4) == 'X') {
3352 /* idea for labels --- end*/
3353 } else if (c != '\0') {
3364 bool LyXParagraph::RoffContTableRows(ostream & os,
3365 LyXParagraph::size_type i,
3371 LyXFont font1(LyXFont::ALL_INHERIT);
3376 string fname2 = TmpFileName(string(), "RAT2");
3378 int cell = table->CellHasContRow(actcell);
3381 // first find the right position
3383 for (; i < size() && actcell < cell; ++i) {
3385 if (c == LyXParagraph::META_NEWLINE)
3390 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3393 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3395 font2 = GetFontSettings(i);
3396 if (font1.latex() != font2.latex()) {
3397 if (font2.latex() != LyXFont::OFF)
3402 case LyXParagraph::META_INSET:
3403 if ((inset = GetInset(i))) {
3406 stringstream ss(ios::in | ios::out);
3407 inset->Latex(ss, true);
3419 inset->Latex(ss, true);
3432 fstream fs(fname2.c_str(),
3435 WriteAlert(_("LYX_ERROR:"),
3436 _("Cannot open temporary file:"),
3440 inset->Latex(fs, true);
3454 case LyXParagraph::META_NEWLINE:
3456 case LyXParagraph::META_HFILL:
3465 lyxerr.debug() << "RoffAsciiTable: "
3466 "NULL char in structure."
3471 cell = table->CellHasContRow(actcell);
3478 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3480 TexRow & foot_texrow,
3483 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3484 LyXParagraph * par = this;
3486 while (par && par->depth == depth) {
3488 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3489 if (textclasslist.Style(current_view->buffer()->params.textclass,
3490 par->layout).isEnvironment()
3491 || par->pextra_type != PEXTRA_NONE) {
3492 par = par->TeXEnvironment(os, texrow,
3496 par = par->TeXOnePar(os, texrow,
3501 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3507 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3509 TexRow & foot_texrow,
3512 bool eindent_open = false;
3513 bool foot_this_level = false;
3514 // flags when footnotetext should be appended to file.
3515 static bool minipage_open = false;
3516 static int minipage_open_depth = 0;
3517 char par_sep = current_view->buffer()->params.paragraph_separation;
3519 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3521 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3523 LyXLayout const & style =
3524 textclasslist.Style(current_view->buffer()->params.textclass,
3527 if (pextra_type == PEXTRA_INDENT) {
3528 if (!pextra_width.empty()) {
3529 os << "\\begin{LyXParagraphIndent}{"
3530 << pextra_width << "}\n";
3532 //float ib = atof(pextra_widthp.c_str())/100;
3533 // string can't handle floats at present (971109)
3534 // so I'll do a conversion by hand knowing that
3535 // the limits are 0.0 to 1.0. ARRae.
3536 os << "\\begin{LyXParagraphIndent}{";
3537 switch (pextra_widthp.length()) {
3549 os << "\\columnwidth}\n";
3552 eindent_open = true;
3554 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3555 if (pextra_hfill && Previous() &&
3556 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3557 os << "\\hfill{}\n";
3560 if (par_sep == BufferParams::PARSEP_INDENT) {
3561 os << "{\\setlength\\parindent{0pt}\n";
3564 os << "\\begin{minipage}";
3565 switch(pextra_alignment) {
3566 case MINIPAGE_ALIGN_TOP:
3569 case MINIPAGE_ALIGN_MIDDLE:
3572 case MINIPAGE_ALIGN_BOTTOM:
3576 if (!pextra_width.empty()) {
3577 os << '{' << pextra_width << "}\n";
3579 //float ib = atof(par->pextra_width.c_str())/100;
3580 // string can't handle floats at present
3581 // so I'll do a conversion by hand knowing that
3582 // the limits are 0.0 to 1.0. ARRae.
3584 switch (pextra_widthp.length()) {
3596 os << "\\columnwidth}\n";
3599 if (par_sep == BufferParams::PARSEP_INDENT) {
3600 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3603 minipage_open = true;
3604 minipage_open_depth = depth;
3607 #ifdef WITH_WARNINGS
3608 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3609 //I disabled it because it breaks when lists span on several
3612 if (style.isEnvironment()){
3613 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3614 #ifdef FANCY_FOOTNOTE_CODE
3615 if (foot_count < 0) {
3616 // flag that footnote[mark][text] should be
3617 // used for any footnotes from now on
3619 foot_this_level = true;
3622 os << "\\begin{" << style.latexname() << "}{"
3623 << labelwidthstring << "}\n";
3624 } else if (style.labeltype == LABEL_BIBLIO) {
3626 os << "\\begin{" << style.latexname() << "}{"
3627 << bibitemWidthest(current_view->painter())
3629 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3630 #ifdef FANCY_FOOTNOTE_CODE
3631 if (foot_count < 0) {
3632 // flag that footnote[mark][text] should be
3633 // used for any footnotes from now on
3635 foot_this_level = true;
3638 os << "\\begin{" << style.latexname() << '}'
3639 << style.latexparam() << '\n';
3641 os << "\\begin{" << style.latexname() << '}'
3642 << style.latexparam() << '\n';
3645 LyXParagraph * par = this;
3647 par = par->TeXOnePar(os, texrow,
3648 foot, foot_texrow, foot_count);
3650 if (minipage_open && par && !style.isEnvironment() &&
3651 (par->pextra_type == PEXTRA_MINIPAGE) &&
3652 par->pextra_start_minipage) {
3653 os << "\\end{minipage}\n";
3655 if (par_sep == BufferParams::PARSEP_INDENT) {
3659 minipage_open = false;
3661 if (par && par->depth > depth) {
3662 if (textclasslist.Style(current_view->buffer()->params.textclass,
3663 par->layout).isParagraph()
3666 // How to handle this? (Lgb)
3667 //&& !suffixIs(os, "\n\n")
3669 // There should be at least one '\n' already
3670 // but we need there to be two for Standard
3671 // paragraphs that are depth-increment'ed to be
3672 // output correctly. However, tables can
3673 // also be paragraphs so don't adjust them.
3676 // Will it ever harm to have one '\n' too
3677 // many? i.e. that we sometimes will have
3678 // three in a row. (Lgb)
3682 par = par->TeXDeeper(os, texrow,
3683 foot, foot_texrow, foot_count);
3685 if (par && par->layout == layout && par->depth == depth &&
3686 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3687 if (par->pextra_hfill && par->Previous() &&
3688 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3689 os << "\\hfill{}\n";
3692 if (par_sep == BufferParams::PARSEP_INDENT) {
3693 os << "{\\setlength\\parindent{0pt}\n";
3696 os << "\\begin{minipage}";
3697 switch(par->pextra_alignment) {
3698 case MINIPAGE_ALIGN_TOP:
3701 case MINIPAGE_ALIGN_MIDDLE:
3704 case MINIPAGE_ALIGN_BOTTOM:
3708 if (!par->pextra_width.empty()) {
3709 os << '{' << par->pextra_width << "}\n";
3711 //float ib = atof(par->pextra_widthp.c_str())/100;
3712 // string can't handle floats at present
3713 // so I'll do a conversion by hand knowing that
3714 // the limits are 0.0 to 1.0. ARRae.
3716 switch (par->pextra_widthp.length()) {
3721 os << "0." << par->pextra_widthp;
3724 os << "0.0" << par->pextra_widthp;
3726 os << "\\columnwidth}\n";
3729 if (par_sep == BufferParams::PARSEP_INDENT) {
3730 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3733 minipage_open = true;
3734 minipage_open_depth = par->depth;
3737 && par->layout == layout
3738 && par->depth == depth
3739 && par->pextra_type == pextra_type);
3741 if (style.isEnvironment()) {
3742 os << "\\end{" << style.latexname() << '}';
3743 // maybe this should go after the minipage closes?
3744 if (foot_this_level) {
3745 if (foot_count >= 1) {
3746 if (foot_count > 1) {
3747 os << "\\addtocounter{footnote}{-"
3752 texrow += foot_texrow;
3754 foot_texrow.reset();
3759 if (minipage_open && (minipage_open_depth == depth) &&
3760 (!par || par->pextra_start_minipage ||
3761 par->pextra_type != PEXTRA_MINIPAGE)) {
3762 os << "\\end{minipage}\n";
3764 if (par_sep == BufferParams::PARSEP_INDENT) {
3768 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3769 os << "\\medskip\n\n";
3773 minipage_open = false;
3776 os << "\\end{LyXParagraphIndent}\n";
3779 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3780 && par->pextra_hfill)) {
3784 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3785 return par; // ale970302
3789 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3790 ostream & foot, TexRow & foot_texrow,
3794 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3795 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3796 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3797 "No footnote!" << endl;
3799 LyXParagraph * par = this;
3800 LyXLayout const & style =
3801 textclasslist.Style(current_view->buffer()->params.textclass,
3802 previous->GetLayout());
3804 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3805 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3806 "Float other than footnote in command"
3807 " with moving argument is illegal" << endl;
3810 if (footnotekind != LyXParagraph::FOOTNOTE
3811 && footnotekind != LyXParagraph::MARGIN
3814 // How to solve this?
3815 //&& !suffixIs(file, '\n')
3817 // we need to ensure that real floats like tables and figures
3818 // have their \begin{} on a new line otherwise we can get
3819 // incorrect results when using the endfloat.sty package
3820 // especially if two floats follow one another. ARRae 981022
3821 // NOTE: if the file is length 0 it must have just been
3822 // written out so we assume it ended with a '\n'
3824 // As far as I can see there is never any harm in writing
3825 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3830 bool need_closing = false;
3831 bool is_rtl = isRightToLeftPar();
3832 if (is_rtl != parent_is_rtl) {
3837 need_closing = true;
3840 BufferParams * params = ¤t_view->buffer()->params;
3841 bool footer_in_body = true;
3842 switch (footnotekind) {
3843 case LyXParagraph::FOOTNOTE:
3844 if (style.intitle) {
3845 os << "\\thanks{\n";
3846 footer_in_body = false;
3848 if (foot_count == -1) {
3849 // we're at depth 0 so we can use:
3850 os << "\\footnote{%\n";
3851 footer_in_body = false;
3853 os << "\\footnotemark{}%\n";
3855 // we only need this when there are
3856 // multiple footnotes
3857 os << "\\stepcounter{footnote}";
3859 os << "\\footnotetext{%\n";
3860 foot_texrow.start(this, 0);
3861 foot_texrow.newline();
3866 case LyXParagraph::MARGIN:
3867 os << "\\marginpar{\n";
3869 case LyXParagraph::FIG:
3870 if (pextra_type == PEXTRA_FLOATFLT
3871 && (!pextra_width.empty()
3872 || !pextra_widthp.empty())) {
3873 if (!pextra_width.empty())
3874 os << "\\begin{floatingfigure}{"
3875 << pextra_width << "}\n";
3877 os << "\\begin{floatingfigure}{"
3878 << atoi(pextra_widthp.c_str())/100.0
3879 << "\\textwidth}\n";
3881 os << "\\begin{figure}";
3882 if (!params->float_placement.empty()) {
3883 os << '[' << params->float_placement << "]\n";
3889 case LyXParagraph::TAB:
3890 os << "\\begin{table}";
3891 if (!params->float_placement.empty()) {
3892 os << '[' << params->float_placement << "]\n";
3897 case LyXParagraph::WIDE_FIG:
3898 os << "\\begin{figure*}";
3899 if (!params->float_placement.empty()) {
3900 os << '[' << params->float_placement << "]\n";
3905 case LyXParagraph::WIDE_TAB:
3906 os << "\\begin{table*}";
3907 if (!params->float_placement.empty()) {
3908 os << '[' << params->float_placement << "]\n";
3913 case LyXParagraph::ALGORITHM:
3914 os << "\\begin{algorithm}\n";
3919 if (footnotekind != LyXParagraph::FOOTNOTE
3920 || !footer_in_body) {
3921 // Process text for all floats except footnotes in body
3923 LyXLayout const & style =
3925 .Style(current_view->buffer()->params
3929 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3931 if (style.isEnvironment()
3932 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3933 // Allows the use of minipages within float
3934 // environments. Shouldn't be circular because
3935 // we don't support footnotes inside
3936 // floats (yet). ARRae
3937 par = par->TeXEnvironment(os, texrow,
3941 par = par->TeXOnePar(os, texrow,
3946 if (par && !par->IsDummy() && par->depth > depth) {
3947 par = par->TeXDeeper(os, texrow,
3951 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3953 // process footnotes > depth 0 or in environments separately
3954 // NOTE: Currently don't support footnotes within footnotes
3955 // even though that is possible using the \footnotemark
3957 std::ostringstream dummy;
3961 TexRow dummy_texrow;
3962 int dummy_count = 0;
3964 LyXLayout const & style =
3966 .Style(current_view->buffer()->params
3970 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3972 if (style.isEnvironment()
3973 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3974 // Allows the use of minipages within float
3975 // environments. Shouldn't be circular because
3976 // we don't support footnotes inside
3977 // floats (yet). ARRae
3978 par = par->TeXEnvironment(foot, foot_texrow,
3979 dummy, dummy_texrow,
3982 par = par->TeXOnePar(foot, foot_texrow,
3983 dummy, dummy_texrow,
3987 if (par && !par->IsDummy() && par->depth > depth) {
3988 par = par->TeXDeeper(foot, foot_texrow,
3989 dummy, dummy_texrow,
3993 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3995 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3996 "Footnote in a Footnote -- not supported"
3999 #ifndef HAVE_OSTREAM
4000 delete [] dummy.str();
4004 switch (footnotekind) {
4005 case LyXParagraph::FOOTNOTE:
4006 if (footer_in_body) {
4007 // This helps tell which of the multiple
4008 // footnotetexts an error was in.
4010 foot_texrow.newline();
4015 case LyXParagraph::MARGIN:
4018 case LyXParagraph::FIG:
4019 if (pextra_type == PEXTRA_FLOATFLT
4020 && (!pextra_width.empty()
4021 || !pextra_widthp.empty()))
4022 os << "\\end{floatingfigure}";
4024 os << "\\end{figure}";
4026 case LyXParagraph::TAB:
4027 os << "\\end{table}";
4029 case LyXParagraph::WIDE_FIG:
4030 os << "\\end{figure*}";
4032 case LyXParagraph::WIDE_TAB:
4033 os << "\\end{table*}";
4035 case LyXParagraph::ALGORITHM:
4036 os << "\\end{algorithm}";
4043 if (footnotekind != LyXParagraph::FOOTNOTE
4044 && footnotekind != LyXParagraph::MARGIN) {
4045 // we need to ensure that real floats like tables and figures
4046 // have their \end{} on a line of their own otherwise we can
4047 // get incorrect results when using the endfloat.sty package.
4052 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4057 bool LyXParagraph::IsDummy() const
4059 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4060 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4064 void LyXParagraph::SetPExtraType(int type, char const * width,
4065 char const * widthp)
4068 pextra_width = width;
4069 pextra_widthp = widthp;
4071 if (textclasslist.Style(current_view->buffer()->params.textclass,
4072 layout).isEnvironment()) {
4077 while (par && (par->layout == layout)
4078 && (par->depth == depth)) {
4080 par = par->Previous();
4082 par = par->FirstPhysicalPar();
4083 while (par && par->depth > depth) {
4084 par = par->Previous();
4086 par = par->FirstPhysicalPar();
4090 while (par && (par->layout == layout)
4091 && (par->depth == depth)) {
4092 par->pextra_type = type;
4093 par->pextra_width = width;
4094 par->pextra_widthp = widthp;
4095 par = par->NextAfterFootnote();
4096 if (par && (par->depth > depth))
4097 par->SetPExtraType(type, width, widthp);
4098 while (par && ((par->depth > depth) || par->IsDummy()))
4099 par = par->NextAfterFootnote();
4105 void LyXParagraph::UnsetPExtraType()
4107 if (pextra_type == PEXTRA_NONE)
4110 pextra_type = PEXTRA_NONE;
4111 pextra_width.clear();
4112 pextra_widthp.clear();
4114 if (textclasslist.Style(current_view->buffer()->params.textclass,
4115 layout).isEnvironment()) {
4120 while (par && (par->layout == layout)
4121 && (par->depth == depth)) {
4123 par = par->Previous();
4125 par = par->FirstPhysicalPar();
4126 while (par && par->depth > depth) {
4127 par = par->Previous();
4129 par = par->FirstPhysicalPar();
4133 while (par && (par->layout == layout)
4134 && (par->depth == depth)) {
4135 par->pextra_type = PEXTRA_NONE;
4136 par->pextra_width.clear();
4137 par->pextra_widthp.clear();
4138 par = par->NextAfterFootnote();
4139 if (par && (par->depth > depth))
4140 par->UnsetPExtraType();
4141 while (par && ((par->depth > depth) || par->IsDummy()))
4142 par = par->NextAfterFootnote();
4148 bool LyXParagraph::IsHfill(size_type pos) const
4150 return IsHfillChar(GetChar(pos));
4154 bool LyXParagraph::IsInset(size_type pos) const
4156 return IsInsetChar(GetChar(pos));
4160 bool LyXParagraph::IsFloat(size_type pos) const
4162 return IsFloatChar(GetChar(pos));
4166 bool LyXParagraph::IsNewline(size_type pos) const
4168 return pos >= 0 && IsNewlineChar(GetChar(pos));
4172 bool LyXParagraph::IsSeparator(size_type pos) const
4174 return IsSeparatorChar(GetChar(pos));
4178 bool LyXParagraph::IsLineSeparator(size_type pos) const
4180 return IsLineSeparatorChar(GetChar(pos));
4184 bool LyXParagraph::IsKomma(size_type pos) const
4186 return IsKommaChar(GetChar(pos));
4190 /// Used by the spellchecker
4191 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4193 unsigned char c = GetChar(pos);
4194 if (IsLetterChar(c))
4196 // '\0' is not a letter, allthough every string contains "" (below)
4199 // We want to pass the ' and escape chars to ispell
4200 string extra = lyxrc.isp_esc_chars + '\'';
4204 return contains(extra, ch);
4208 bool LyXParagraph::IsWord(size_type pos ) const
4210 return IsWordChar(GetChar(pos)) ;
4214 Language const * LyXParagraph::getParLanguage() const
4218 return FirstPhysicalPar()->GetFirstFontSettings()
4221 for (size_type pos = 0; pos < size(); ++pos)
4223 return GetFontSettings(pos).language();
4224 return GetFirstFontSettings().language();
4227 return previous->getParLanguage();
4229 return current_view->buffer()->params.language_info;
4233 bool LyXParagraph::isRightToLeftPar() const
4235 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4239 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4241 for(size_type i = 0; i < size(); ++i) {
4242 LyXFont font = GetFontSettings(i);
4243 if (font.language() == from) {
4244 font.setLanguage(to);
4251 bool LyXParagraph::isMultiLingual()
4253 Language const * doc_language =
4254 current_view->buffer()->params.language_info;
4255 for(size_type i = 0; i < size(); ++i) {
4256 LyXFont font = GetFontSettings(i);
4257 if (font.language() != doc_language)