1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
25 #include "tex-strings.h"
26 #include "bufferparams.h"
27 #include "support/FileInfo.h"
28 #include "support/LAssert.h"
30 #include "LaTeXFeatures.h"
31 #include "insets/insetinclude.h"
32 #include "insets/insetbib.h"
33 #include "support/filetools.h"
34 #include "lyx_gui_misc.h"
38 extern void addNewlineAndDepth(string & file, int depth); // Jug 990923
39 int tex_code_break_column = 72; // needs non-zero initialization. set later.
40 // this is a bad idea, but how can LyXParagraph find its buffer to get
41 // parameters? (JMarc)
42 extern BufferView * current_view;
47 extern string bibitemWidthest(Painter &);
49 // this is a minibuffer
50 static char minibuffer_char;
51 static LyXFont minibuffer_font;
52 static Inset * minibuffer_inset;
55 // Initialization of the counter for the paragraph id's,
56 // declared in lyxparagraph.h
57 unsigned int LyXParagraph::paragraph_id = 0;
60 LyXParagraph::LyXParagraph()
62 text.reserve(500); // is this number too big?
64 for (int i = 0; i < 10; ++i) setCounter(i , 0);
70 footnoteflag = LyXParagraph::NO_FOOTNOTE;
71 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
73 align = LYX_ALIGN_BLOCK;
75 /* table stuff -- begin*/
77 /* table stuff -- end*/
79 bibkey = 0; // ale970302
84 // This konstruktor inserts the new paragraph in a list.
85 LyXParagraph::LyXParagraph(LyXParagraph * par)
88 par->text.resize(par->text.size());
90 for (int i = 0; i < 10; ++i) setCounter(i, 0);
94 // double linked list begin
97 next->previous = this;
99 previous->next = this;
101 footnoteflag = LyXParagraph::NO_FOOTNOTE;
102 footnotekind = LyXParagraph::FOOTNOTE;
104 /* table stuff -- begin*/
106 /* table stuff -- end*/
107 id_ = paragraph_id++;
109 bibkey = 0; // ale970302
115 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
116 char footflag, char dth) const
118 LyXFont font1, font2;
123 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
125 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
127 // The beginning or the end of a footnote environment?
128 if (footflag != footnoteflag) {
129 footflag = footnoteflag;
131 os << "\n\\begin_float "
132 << string_footnotekinds[footnotekind]
135 os << "\n\\end_float ";
139 // The beginning or end of a deeper (i.e. nested) area?
142 while (depth > dth) {
143 os << "\n\\begin_deeper ";
147 while (depth < dth) {
148 os << "\n\\end_deeper ";
154 // First write the layout
156 << textclasslist.NameOfLayout(params.textclass, layout)
159 // Maybe some vertical spaces.
160 if (added_space_top.kind() != VSpace::NONE)
161 os << "\\added_space_top "
162 << added_space_top.asLyXCommand() << " ";
163 if (added_space_bottom.kind() != VSpace::NONE)
164 os << "\\added_space_bottom "
165 << added_space_bottom.asLyXCommand() << " ";
167 // The labelwidth string used in lists.
168 if (!labelwidthstring.empty())
169 os << "\\labelwidthstring "
170 << labelwidthstring << '\n';
172 // Lines above or below?
176 os << "\\line_bottom ";
178 // Pagebreaks above or below?
180 os << "\\pagebreak_top ";
181 if (pagebreak_bottom)
182 os << "\\pagebreak_bottom ";
184 // Start of appendix?
185 if (start_of_appendix)
186 os << "\\start_of_appendix ";
193 if (align != LYX_ALIGN_LAYOUT) {
195 case LYX_ALIGN_LEFT: h = 1; break;
196 case LYX_ALIGN_RIGHT: h = 2; break;
197 case LYX_ALIGN_CENTER: h = 3; break;
198 default: h = 0; break;
200 os << "\\align " << string_align[h] << " ";
202 if (pextra_type != PEXTRA_NONE) {
203 os << "\\pextra_type " << pextra_type;
204 if (pextra_type == PEXTRA_MINIPAGE) {
205 os << " \\pextra_alignment "
208 os << " \\pextra_hfill "
210 if (pextra_start_minipage)
211 os << " \\pextra_start_minipage "
212 << pextra_start_minipage;
214 if (!pextra_width.empty()) {
215 os << " \\pextra_width "
216 << VSpace(pextra_width).asLyXCommand();
217 } else if (!pextra_widthp.empty()) {
218 os << " \\pextra_widthp "
224 // Dummy layout. This means that a footnote ended.
225 os << "\n\\end_float ";
226 footflag = LyXParagraph::NO_FOOTNOTE;
229 // It might be a table.
231 os << "\\LyXTable\n";
239 font1 = LyXFont(LyXFont::ALL_INHERIT);
242 for (size_type i = 0; i < size(); ++i) {
248 // Write font changes
249 font2 = GetFontSettings(i);
250 if (font2 != font1) {
251 font2.lyxWriteChanges(font1, os);
260 Inset const * inset = GetInset(i);
262 if (inset->DirectWrite()) {
263 // international char, let it write
264 // code directly so it's shorter in
268 os << "\n\\begin_inset ";
270 os << "\n\\end_inset \n\n";
276 os << "\n\\newline \n";
280 os << "\n\\hfill \n";
284 case META_PROTECTED_SEPARATOR:
285 os << "\n\\protected_separator \n";
290 os << "\n\\backslash \n";
294 if (i + 1 < size() && GetChar(i + 1) == ' ') {
301 if ((column > 70 && c == ' ')
306 // this check is to amend a bug. LyX sometimes
307 // inserts '\0' this could cause problems.
311 lyxerr << "ERROR (LyXParagraph::writeFile):"
312 " NULL char in structure." << endl;
318 // now write the next paragraph
320 next->writeFile(os, params, footflag, dth);
324 void LyXParagraph::validate(LaTeXFeatures & features) const
326 // this will be useful later
327 LyXLayout const & layout =
328 textclasslist.Style(current_view->buffer()->params.textclass,
332 if (line_top || line_bottom)
333 features.lyxline = true;
336 features.layout[GetLayout()] = true;
339 for (FontList::const_iterator cit = fontlist.begin();
340 cit != fontlist.end(); ++cit) {
341 if ((*cit).font.noun() == LyXFont::ON) {
342 lyxerr[Debug::LATEX] << "font.noun: "
343 << (*cit).font.noun()
345 features.noun = true;
346 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
347 << (*cit).font.stateText()
350 switch ((*cit).font.color()) {
352 case LColor::inherit:
356 features.color = true;
357 lyxerr[Debug::LATEX] << "Color enabled. Font: "
358 << (*cit).font.stateText()
364 for (InsetList::const_iterator cit = insetlist.begin();
365 cit != insetlist.end(); ++cit) {
367 (*cit).inset->Validate(features);
370 if (table && table->IsLongTable())
371 features.longtable = true;
372 if (pextra_type == PEXTRA_INDENT)
373 features.LyXParagraphIndent = true;
374 if (pextra_type == PEXTRA_FLOATFLT)
375 features.floatflt = true;
376 if (layout.needprotect
377 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
378 features.NeedLyXFootnoteCode = true;
379 if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
380 (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
381 features.NeedLyXMinipageIndent = true;
382 if (table && table->NeedRotating())
383 features.rotating = true;
384 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
385 features.algorithm = true;
389 // First few functions needed for cut and paste and paragraph breaking.
390 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
392 minibuffer_char = GetChar(pos);
393 minibuffer_font = GetFontSettings(pos);
394 minibuffer_inset = 0;
395 if (minibuffer_char == LyXParagraph::META_INSET) {
397 minibuffer_inset = GetInset(pos)->Clone();
399 minibuffer_inset = 0;
400 minibuffer_char = ' ';
401 // This reflects what GetInset() does (ARRae)
407 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
409 minibuffer_char = GetChar(pos);
410 minibuffer_font = GetFontSettings(pos);
411 minibuffer_inset = 0;
412 if (minibuffer_char == LyXParagraph::META_INSET) {
414 minibuffer_inset = GetInset(pos);
415 // This is a little hack since I want exactly
416 // the inset, not just a clone. Otherwise
417 // the inset would be deleted when calling Erase(pos)
419 for (InsetList::iterator it = insetlist.begin();
420 it != insetlist.end(); ++it) {
421 if ((*it).pos == pos) {
428 minibuffer_inset = 0;
429 minibuffer_char = ' ';
430 // This reflects what GetInset() does (ARRae)
435 // Erase(pos); now the caller is responsible for that.
439 void LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
441 InsertChar(pos, minibuffer_char);
442 SetFont(pos, minibuffer_font);
443 if (minibuffer_char == LyXParagraph::META_INSET)
444 InsertInset(pos, minibuffer_inset);
451 void LyXParagraph::Clear()
456 pagebreak_top = false;
457 pagebreak_bottom = false;
459 added_space_top = VSpace(VSpace::NONE);
460 added_space_bottom = VSpace(VSpace::NONE);
462 align = LYX_ALIGN_LAYOUT;
466 pextra_type = PEXTRA_NONE;
467 pextra_width.clear();
468 pextra_widthp.clear();
469 pextra_alignment = MINIPAGE_ALIGN_TOP;
470 pextra_hfill = false;
471 pextra_start_minipage = false;
474 labelwidthstring.clear();
478 start_of_appendix = false;
482 // the destructor removes the new paragraph from the list
483 LyXParagraph::~LyXParagraph()
486 previous->next = next;
488 next->previous = previous;
490 for (InsetList::iterator it = insetlist.begin();
491 it != insetlist.end(); ++it) {
495 /* table stuff -- begin*/
497 /* table stuff -- end*/
504 void LyXParagraph::Erase(LyXParagraph::size_type pos)
506 // > because last is the next unused position, and you can
507 // use it if you want
509 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
510 NextAfterFootnote()->Erase(pos - text.size() - 1);
512 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
513 "position does not exist." << endl;
516 if (pos < size()) { // last is free for insertation, but should be empty
517 // if it is an inset, delete the inset entry
518 if (text[pos] == LyXParagraph::META_INSET) {
520 for (InsetList::iterator it = insetlist.begin();
521 it != insetlist.end(); ++it) {
522 if ((*it).pos == pos) {
529 text.erase(text.begin() + pos);
530 // Erase entries in the tables.
531 for (FontList::iterator it = fontlist.begin();
532 it != fontlist.end(); ++it) {
533 if (pos >= (*it).pos && pos <= (*it).pos_end) {
534 if ((*it).pos == (*it).pos_end) {
535 // If it is a multi-character font
536 // entry, we just make it smaller
537 // (see update below), otherwise we
544 // Update all other entries.
545 for (FontList::iterator it = fontlist.begin();
546 it != fontlist.end(); ++it) {
549 if ((*it).pos_end >= pos)
553 // Update the inset table.
554 for (InsetList::iterator it = insetlist.begin();
555 it != insetlist.end(); ++it) {
560 lyxerr << "ERROR (LyXParagraph::Erase): "
561 "can't erase non-existant char." << endl;
566 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
568 // > because last is the next unused position, and you can
569 // use it if you want
572 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
573 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
576 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
577 "position does not exist." << endl;
580 text.insert(text.begin() + pos, c);
581 // Update the font table.
582 for (FontList::iterator it = fontlist.begin();
583 it != fontlist.end(); ++it) {
584 if ((*it).pos >= pos)
586 if ((*it).pos_end >= pos)
590 // Update the inset table.
591 for (InsetList::iterator it = insetlist.begin();
592 it != insetlist.end(); ++it) {
593 if ((*it).pos >= pos)
599 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
602 // > because last is the next unused position, and you can
603 // use it if you want
606 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
608 ->InsertInset(pos - text.size() - 1, inset);
610 lyxerr << "ERROR (LyXParagraph::InsertInset): "
611 "position does not exist: " << pos << endl;
614 if (text[pos] != LyXParagraph::META_INSET) {
615 lyxerr << "ERROR (LyXParagraph::InsertInset): "
616 "there is no LyXParagraph::META_INSET" << endl;
621 // Add a new entry in the inset table.
622 InsetList::iterator it =
623 insetlist.insert(insetlist.begin(), InsetTable());
630 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
634 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
635 return NextAfterFootnote()
636 ->GetInset(pos - text.size() - 1);
638 lyxerr << "ERROR (LyXParagraph::GetInset): "
639 "position does not exist: "
645 for (InsetList::iterator it = insetlist.begin();
646 it != insetlist.end(); ++it) {
647 if ((*it).pos == pos) {
651 lyxerr << "ERROR (LyXParagraph::GetInset): "
652 "Inset does not exist: " << pos << endl;
653 text[pos] = ' '; // WHY!!! does this set the pos to ' '????
654 // Did this commenting out introduce a bug? So far I have not
655 // see any, please enlighten me. (Lgb)
656 // My guess is that since the inset does not exist, we might
657 // as well replace it with a space to prevent craches. (Asger)
662 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
666 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
667 return NextAfterFootnote()
668 ->GetInset(pos - text.size() - 1);
670 lyxerr << "ERROR (LyXParagraph::GetInset): "
671 "position does not exist: "
677 for (InsetList::const_iterator cit = insetlist.begin();
678 cit != insetlist.end(); ++cit) {
679 if ((*cit).pos == pos) {
683 lyxerr << "ERROR (LyXParagraph::GetInset): "
684 "Inset does not exist: " << pos << endl;
685 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
686 // Did this commenting out introduce a bug? So far I have not
687 // see any, please enlighten me. (Lgb)
688 // My guess is that since the inset does not exist, we might
689 // as well replace it with a space to prevent craches. (Asger)
694 // Gets uninstantiated font setting at position.
695 // Optimized after profiling. (Asger)
696 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
699 for (FontList::const_iterator cit = fontlist.begin();
700 cit != fontlist.end(); ++cit) {
701 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
705 // > because last is the next unused position, and you can
706 // use it if you want
707 else if (pos > size()) {
709 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
710 return NextAfterFootnote()
711 ->GetFontSettings(pos - text.size() - 1);
713 // Why is it an error to ask for the font of a
714 // position that does not exist? Would it be
715 // enough for this to be enabled on debug?
716 // We want strict error checking, but it's ok to only
717 // have it when debugging. (Asger)
718 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
719 "position does not exist. "
720 << pos << " (" << static_cast<int>(pos)
724 return GetFontSettings(pos - 1);
726 return LyXFont(LyXFont::ALL_INHERIT);
730 // Gets the fully instantiated font at a given position in a paragraph
731 // This is basically the same function as LyXText::GetFont() in text2.C.
732 // The difference is that this one is used for generating the LaTeX file,
733 // and thus cosmetic "improvements" are disallowed: This has to deliver
734 // the true picture of the buffer. (Asger)
735 // If position is -1, we get the layout font of the paragraph.
736 // If position is -2, we get the font of the manual label of the paragraph.
737 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
740 LyXLayout const & layout =
741 textclasslist.Style(current_view->buffer()->params.textclass,
743 LyXParagraph::size_type main_body = 0;
744 if (layout.labeltype == LABEL_MANUAL)
745 main_body = BeginningOfMainBody();
750 layoutfont = layout.labelfont;
752 layoutfont = layout.font;
753 tmpfont = GetFontSettings(pos);
754 tmpfont.realize(layoutfont);
756 // process layoutfont for pos == -1 and labelfont for pos < -1
758 tmpfont = layout.font;
760 tmpfont = layout.labelfont;
761 if (getParDirection() == LYX_DIR_RIGHT_TO_LEFT)
762 tmpfont.setDirection(LyXFont::RTL_DIR);
765 // check for environment font information
766 char par_depth = GetDepth();
767 LyXParagraph const * par = this;
768 while (par && par_depth && !tmpfont.resolved()) {
769 par = par->DepthHook(par_depth - 1);
771 tmpfont.realize(textclasslist.
772 Style(current_view->buffer()->params.textclass,
773 par->GetLayout()).font);
774 par_depth = par->GetDepth();
778 tmpfont.realize(textclasslist
779 .TextClass(current_view->buffer()->params.textclass)
785 /// Returns the height of the highest font in range
787 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
788 LyXParagraph::size_type endpos) const
790 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
791 for (FontList::const_iterator cit = fontlist.begin();
792 cit != fontlist.end(); ++cit) {
793 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
794 LyXFont::FONT_SIZE size = (*cit).font.size();
795 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
803 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
810 // > because last is the next unused position, and you can
811 // use it if you want
812 else if (pos > size()) {
813 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
814 return NextAfterFootnote()
815 ->GetChar(pos - text.size() - 1);
817 lyxerr << "ERROR (LyXParagraph::GetChar): "
818 "position does not exist."
819 << pos << " (" << static_cast<int>(pos)
821 // Assert(false); // This triggers sometimes...
826 // We should have a footnote environment.
827 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
828 // Notice that LyX does request the
829 // last char from time to time. (Asger)
830 //lyxerr << "ERROR (LyXParagraph::GetChar): "
831 // "expected footnote." << endl;
834 switch (next->footnotekind) {
835 case LyXParagraph::FOOTNOTE:
836 return LyXParagraph::META_FOOTNOTE;
837 case LyXParagraph::MARGIN:
838 return LyXParagraph::META_MARGIN;
839 case LyXParagraph::FIG:
840 case LyXParagraph::WIDE_FIG:
841 return LyXParagraph::META_FIG;
842 case LyXParagraph::TAB:
843 case LyXParagraph::WIDE_TAB:
844 return LyXParagraph::META_TAB;
845 case LyXParagraph::ALGORITHM:
846 return LyXParagraph::META_ALGORITHM;
848 return '\0'; // to shut up gcc
853 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
860 // > because last is the next unused position, and you can
861 // use it if you want
862 else if (pos > size()) {
863 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
864 return NextAfterFootnote()
865 ->GetChar(pos - text.size() - 1);
867 lyxerr << "ERROR (LyXParagraph::GetChar const): "
868 "position does not exist."
869 << pos << " (" << static_cast<int>(pos)
875 // We should have a footnote environment.
876 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
877 // Notice that LyX does request the
878 // last char from time to time. (Asger)
879 //lyxerr << "ERROR (LyXParagraph::GetChar): "
880 // "expected footnote." << endl;
883 switch (next->footnotekind) {
884 case LyXParagraph::FOOTNOTE:
885 return LyXParagraph::META_FOOTNOTE;
886 case LyXParagraph::MARGIN:
887 return LyXParagraph::META_MARGIN;
888 case LyXParagraph::FIG:
889 case LyXParagraph::WIDE_FIG:
890 return LyXParagraph::META_FIG;
891 case LyXParagraph::TAB:
892 case LyXParagraph::WIDE_TAB:
893 return LyXParagraph::META_TAB;
894 case LyXParagraph::ALGORITHM:
895 return LyXParagraph::META_ALGORITHM;
897 return '\0'; // to shut up gcc
902 // return an string of the current word, and the end of the word in lastpos.
903 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
907 // the current word is defined as starting at the first character
908 // from the immediate left of lastpospos which meets the definition
909 // of IsLetter(), continuing to the last character to the right
910 // of this meeting IsLetter.
916 // move back until we have a letter
918 //there's no real reason to have firstpos & lastpos as
919 //separate variables as this is written, but maybe someon
920 // will want to return firstpos in the future.
922 //since someone might have typed a punctuation first
923 int firstpos = lastpos;
925 while ((firstpos >= 0) && !IsLetter(firstpos))
928 // now find the beginning by looking for a nonletter
930 while ((firstpos>= 0) && IsLetter(firstpos))
933 // the above is now pointing to the preceeding non-letter
937 // so copy characters into theword until we get a nonletter
938 // note that this can easily exceed lastpos, wich means
939 // that if used in the middle of a word, the whole word
942 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
949 LyXParagraph::size_type LyXParagraph::Last() const
951 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
952 return text.size() + NextAfterFootnote()->Last() + 1;
953 // the 1 is the symbol
960 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
962 // > because last is the next unused position, and you can
963 // use it if you want
966 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
967 return NextAfterFootnote()
968 ->ParFromPos(pos - text.size() - 1);
970 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
971 "position does not exist." << endl;
978 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
980 // > because last is the next unused position, and you can
981 // use it if you want
984 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
985 return NextAfterFootnote()
986 ->PositionInParFromPos(pos - text.size() - 1);
989 "ERROR (LyXParagraph::PositionInParFromPos): "
990 "position does not exist." << endl;
998 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
999 LyXFont const & font)
1001 // > because last is the next unused position, and you can
1002 // use it if you want
1005 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1006 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1009 lyxerr << "ERROR (LyXParagraph::SetFont): "
1010 "position does not exist." << endl;
1014 LyXFont patternfont(LyXFont::ALL_INHERIT);
1016 // First, reduce font against layout/label font
1017 // Update: The SetCharFont() routine in text2.C already
1018 // reduces font, so we don't need to do that here. (Asger)
1019 // No need to simplify this because it will disappear
1020 // in a new kernel. (Asger)
1021 // Next search font table
1022 FontList::iterator tmp = fontlist.begin();
1023 for (; tmp != fontlist.end(); ++tmp) {
1024 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1028 if (tmp == fontlist.end()) { // !found
1029 // if we did not find a font entry, but if the font at hand
1030 // is the same as default, we just forget it
1031 if (font == patternfont) return;
1033 // ok, we did not find a font entry. But maybe there is exactly
1034 // the needed font ientry one position left
1035 FontList::iterator tmp2 = fontlist.begin();
1036 for (; tmp2 != fontlist.end(); ++tmp2) {
1037 if (pos - 1 >= (*tmp2).pos
1038 && pos - 1 <= (*tmp2).pos_end)
1041 if (tmp2 != fontlist.end()) {
1042 // ok there is one, maybe it is exactly
1044 if ((*tmp2).font == font) {
1045 // put the position under the font
1050 // Add a new entry in the
1051 // fontlist for the position
1055 ft.font = font; // or patternfont
1056 // It seems that using font instead of patternfont here
1057 // fixes all the problems. This also surfaces a "bug" in
1059 fontlist.insert(fontlist.begin(), ft);
1060 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1062 // more than one character
1063 if (pos == (*tmp).pos) {
1064 // maybe we should enlarge the left fonttable
1065 FontList::iterator tmp2 = fontlist.begin();
1066 for (; tmp2 != fontlist.end(); ++tmp2) {
1067 if (pos - 1 >= (*tmp2).pos
1068 && pos - 1 <= (*tmp2).pos_end)
1071 // Is there is one, and is it exactly
1073 if (tmp2 != fontlist.end() &&
1074 (*tmp2).font == font) {
1075 // Put the position under the font
1081 // Add a new entry in the
1082 // fontlist for the position
1085 ft.pos_end = (*tmp).pos_end;
1086 ft.font = (*tmp).font;
1087 (*tmp).pos_end = pos;
1089 fontlist.insert(fontlist.begin(), ft);
1090 } else if (pos == (*tmp).pos_end) {
1091 // Add a new entry in the
1092 // fontlist for the position
1094 ft.pos = (*tmp).pos;
1095 ft.pos_end = (*tmp).pos_end - 1;
1096 ft.font = (*tmp).font;
1097 (*tmp).pos = (*tmp).pos_end;
1099 fontlist.insert(fontlist.begin(), ft);
1101 // Add a new entry in the
1102 // fontlist for the position
1104 ft.pos = (*tmp).pos;
1105 ft.pos_end = pos - 1;
1106 ft.font = (*tmp).font;
1110 ft2.pos_end = (*tmp).pos_end;
1111 ft2.font = (*tmp).font;
1114 (*tmp).pos_end = pos;
1117 fontlist.insert(fontlist.begin(), ft);
1118 fontlist.insert(fontlist.begin(), ft2);
1126 // This function is able to hide closed footnotes.
1127 LyXParagraph * LyXParagraph::Next()
1129 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1130 LyXParagraph * tmp = next;
1132 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1134 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1135 return tmp->Next(); /* there can be more than one
1136 footnote in a logical
1139 return next; // This should never happen!
1145 LyXParagraph * LyXParagraph::NextAfterFootnote()
1147 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1148 LyXParagraph * tmp = next;
1149 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1151 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1152 return tmp; /* there can be more than one footnote
1153 in a logical paragraph */
1155 return next; // This should never happen!
1161 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1163 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1164 LyXParagraph * tmp = next;
1165 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1167 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1168 return tmp; /* there can be more than one footnote
1169 in a logical paragraph */
1171 return next; // This should never happen!
1177 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1180 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1182 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1183 tmp = tmp->previous;
1184 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1185 return tmp; /* there can be more than one footnote
1186 in a logical paragraph */
1188 return previous; // This should never happen!
1194 LyXParagraph * LyXParagraph::LastPhysicalPar()
1196 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1199 LyXParagraph * tmp = this;
1201 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1202 tmp = tmp->NextAfterFootnote();
1209 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1213 LyXParagraph * tmppar = this;
1217 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1218 tmppar = tmppar->previous;
1227 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1231 LyXParagraph const * tmppar = this;
1235 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1236 tmppar = tmppar->previous;
1245 // This function is able to hide closed footnotes.
1246 LyXParagraph * LyXParagraph::Previous()
1248 LyXParagraph * tmp = previous;
1253 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1254 tmp = tmp->previous;
1256 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1257 tmp = tmp->previous;
1258 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1259 return tmp->next->Previous();
1268 // This function is able to hide closed footnotes.
1269 LyXParagraph const * LyXParagraph::Previous() const
1271 LyXParagraph * tmp = previous;
1276 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1277 tmp = tmp->previous;
1279 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1280 tmp = tmp->previous;
1281 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1282 return tmp->next->Previous();
1291 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1294 size_type i, pos_end, pos_first;
1295 // create a new paragraph
1296 LyXParagraph * par = ParFromPos(pos);
1297 LyXParagraph * firstpar = FirstPhysicalPar();
1299 LyXParagraph * tmp = new LyXParagraph(par);
1301 tmp->footnoteflag = footnoteflag;
1302 tmp->footnotekind = footnotekind;
1304 // this is an idea for a more userfriendly layout handling, I will
1305 // see what the users say
1307 // layout stays the same with latex-environments
1309 tmp->SetOnlyLayout(firstpar->layout);
1310 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1313 if (Last() > pos || !Last() || flag == 2) {
1314 tmp->SetOnlyLayout(firstpar->layout);
1315 tmp->align = firstpar->align;
1316 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1318 tmp->line_bottom = firstpar->line_bottom;
1319 firstpar->line_bottom = false;
1320 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1321 firstpar->pagebreak_bottom = false;
1322 tmp->added_space_bottom = firstpar->added_space_bottom;
1323 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1325 tmp->depth = firstpar->depth;
1326 tmp->noindent = firstpar->noindent;
1328 // copy everything behind the break-position
1329 // to the new paragraph
1331 while (ParFromPos(pos_first) != par)
1334 pos_end = pos_first + par->text.size() - 1;
1335 // The constructor has already reserved 500 elements
1336 //if (pos_end > pos)
1337 // tmp->text.reserve(pos_end - pos);
1339 for (i = pos; i <= pos_end; ++i) {
1340 par->CutIntoMinibuffer(i - pos_first);
1341 tmp->InsertFromMinibuffer(i - pos);
1343 tmp->text.resize(tmp->text.size());
1344 for (i = pos_end; i >= pos; --i)
1345 par->Erase(i - pos_first);
1347 par->text.resize(par->text.size());
1350 // just an idea of me
1352 tmp->line_top = firstpar->line_top;
1353 tmp->pagebreak_top = firstpar->pagebreak_top;
1354 tmp->added_space_top = firstpar->added_space_top;
1355 tmp->bibkey = firstpar->bibkey;
1357 // layout stays the same with latex-environments
1359 firstpar->SetOnlyLayout(tmp->layout);
1360 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1361 firstpar->depth = tmp->depth;
1367 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1369 par = par->FirstPhysicalPar();
1370 footnoteflag = par->footnoteflag;
1371 footnotekind = par->footnotekind;
1373 layout = par->layout;
1374 align = par-> align;
1375 SetLabelWidthString(par->labelwidthstring);
1377 line_bottom = par->line_bottom;
1378 pagebreak_bottom = par->pagebreak_bottom;
1379 added_space_bottom = par->added_space_bottom;
1381 line_top = par->line_top;
1382 pagebreak_top = par->pagebreak_top;
1383 added_space_top = par->added_space_top;
1385 pextra_type = par->pextra_type;
1386 pextra_width = par->pextra_width;
1387 pextra_widthp = par->pextra_widthp;
1388 pextra_alignment = par->pextra_alignment;
1389 pextra_hfill = par->pextra_hfill;
1390 pextra_start_minipage = par->pextra_start_minipage;
1392 noindent = par->noindent;
1397 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1399 LyXParagraph * tmppar = this;
1402 && tmppar->previous->footnoteflag ==
1403 LyXParagraph::CLOSED_FOOTNOTE)
1404 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1405 tmppar = tmppar->previous;
1408 return this; // This should never happen!
1414 LyXParagraph * LyXParagraph::Clone() const
1416 // create a new paragraph
1417 LyXParagraph * result = new LyXParagraph;
1419 result->MakeSameLayout(this);
1421 // this is because of the dummy layout of the paragraphs that
1423 result->layout = layout;
1425 /* table stuff -- begin*/
1427 result->table = table->Clone();
1430 /* table stuff -- end*/
1433 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1436 // copy everything behind the break-position to the new paragraph
1438 for (size_type i = 0; i < size(); ++i) {
1439 CopyIntoMinibuffer(i);
1440 result->InsertFromMinibuffer(i);
1442 result->text.resize(result->text.size());
1447 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1449 par = par->FirstPhysicalPar();
1452 par->footnoteflag == footnoteflag &&
1453 par->footnotekind == footnotekind &&
1455 par->layout == layout &&
1457 par->align == align &&
1459 par->line_bottom == line_bottom &&
1460 par->pagebreak_bottom == pagebreak_bottom &&
1461 par->added_space_bottom == added_space_bottom &&
1463 par->line_top == line_top &&
1464 par->pagebreak_top == pagebreak_top &&
1465 par->added_space_top == added_space_top &&
1467 par->pextra_type == pextra_type &&
1468 par->pextra_width == pextra_width &&
1469 par->pextra_widthp == pextra_widthp &&
1470 par->pextra_alignment == pextra_alignment &&
1471 par->pextra_hfill == pextra_hfill &&
1472 par->pextra_start_minipage == pextra_start_minipage &&
1474 par->table == table && // what means: NO TABLE AT ALL
1476 par->noindent == noindent &&
1477 par->depth == depth);
1481 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1483 // create a new paragraph
1484 LyXParagraph * par = ParFromPos(pos);
1486 LyXParagraph * tmp = new LyXParagraph(par);
1488 tmp->MakeSameLayout(par);
1490 // When can pos < Last()?
1491 // I guess pos == Last() is possible.
1493 // copy everything behind the break-position to the new
1495 size_type pos_first = 0;
1496 while (ParFromPos(pos_first) != par)
1498 size_type pos_end = pos_first + par->text.size() - 1;
1499 // make sure there is enough memory for the now larger
1500 // paragraph. This is not neccessary, because
1501 // InsertFromMinibuffer will enlarge the memory (it uses
1502 // InsertChar of course). But doing it by hand
1503 // is MUCH faster! (only one time, not thousend times!!)
1504 // Not needed since the constructor aleady have
1505 // reserved 500 elements in text.
1506 //if (pos_end > pos)
1507 // tmp->text.reserve(pos_end - pos);
1509 for (size_type i = pos; i <= pos_end; ++i) {
1510 par->CutIntoMinibuffer(i - pos_first);
1511 tmp->InsertFromMinibuffer(i - pos);
1513 tmp->text.resize(tmp->text.size());
1514 for (size_type i = pos_end; i >= pos; --i)
1515 par->Erase(i - pos_first);
1517 par->text.resize(par->text.size());
1522 // Be carefull, this does not make any check at all.
1523 void LyXParagraph::PasteParagraph()
1525 // copy the next paragraph to this one
1526 LyXParagraph * the_next = Next();
1528 LyXParagraph * firstpar = FirstPhysicalPar();
1530 // first the DTP-stuff
1531 firstpar->line_bottom = the_next->line_bottom;
1532 firstpar->added_space_bottom = the_next->added_space_bottom;
1533 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1535 size_type pos_end = the_next->text.size() - 1;
1536 size_type pos_insert = Last();
1538 // ok, now copy the paragraph
1539 for (size_type i = 0; i <= pos_end; ++i) {
1540 the_next->CutIntoMinibuffer(i);
1541 InsertFromMinibuffer(pos_insert + i);
1544 // delete the next paragraph
1549 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1551 LyXParagraph * par = ParFromPos(pos);
1553 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1554 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1560 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1562 LyXParagraph * par = ParFromPos(pos);
1564 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1565 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1571 LyXTextClass::size_type LyXParagraph::GetLayout() const
1573 return FirstPhysicalPar()->layout;
1577 char LyXParagraph::GetDepth() const
1579 return FirstPhysicalPar()->depth;
1583 char LyXParagraph::GetAlign() const
1585 return FirstPhysicalPar()->align;
1589 string LyXParagraph::GetLabestring() const
1591 return FirstPhysicalPar()->labelstring;
1595 int LyXParagraph::GetFirstCounter(int i) const
1597 return FirstPhysicalPar()->counter_[i];
1601 // the next two functions are for the manual labels
1602 string LyXParagraph::GetLabelWidthString() const
1604 if (!FirstPhysicalPar()->labelwidthstring.empty())
1605 return FirstPhysicalPar()->labelwidthstring;
1607 return _("Senseless with this layout!");
1611 void LyXParagraph::SetLabelWidthString(string const & s)
1613 LyXParagraph * par = FirstPhysicalPar();
1615 par->labelwidthstring = s;
1619 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1621 LyXParagraph * par = FirstPhysicalPar();
1622 LyXParagraph * ppar = 0;
1623 LyXParagraph * npar = 0;
1625 par->layout = new_layout;
1626 /* table stuff -- begin*/
1629 /* table stuff -- end*/
1630 if (par->pextra_type == PEXTRA_NONE) {
1631 if (par->Previous()) {
1632 ppar = par->Previous()->FirstPhysicalPar();
1635 && (ppar->depth > par->depth))
1636 ppar = ppar->Previous()->FirstPhysicalPar();
1639 npar = par->Next()->NextAfterFootnote();
1642 && (npar->depth > par->depth))
1643 npar = npar->Next()->NextAfterFootnote();
1645 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1647 p1 = ppar->pextra_width,
1648 p2 = ppar->pextra_widthp;
1649 ppar->SetPExtraType(ppar->pextra_type,
1650 p1.c_str(), p2.c_str());
1652 if ((par->pextra_type == PEXTRA_NONE) &&
1653 npar && (npar->pextra_type != PEXTRA_NONE)) {
1655 p1 = npar->pextra_width,
1656 p2 = npar->pextra_widthp;
1657 npar->SetPExtraType(npar->pextra_type,
1658 p1.c_str(), p2.c_str());
1664 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1667 * par = FirstPhysicalPar(),
1671 par->layout = new_layout;
1672 par->labelwidthstring.clear();
1673 par->align = LYX_ALIGN_LAYOUT;
1674 par->added_space_top = VSpace(VSpace::NONE);
1675 par->added_space_bottom = VSpace(VSpace::NONE);
1676 /* table stuff -- begin*/
1679 /* table stuff -- end*/
1680 if (par->pextra_type == PEXTRA_NONE) {
1681 if (par->Previous()) {
1682 ppar = par->Previous()->FirstPhysicalPar();
1685 && (ppar->depth > par->depth))
1686 ppar = ppar->Previous()->FirstPhysicalPar();
1689 npar = par->Next()->NextAfterFootnote();
1692 && (npar->depth > par->depth))
1693 npar = npar->Next()->NextAfterFootnote();
1695 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1697 p1 = ppar->pextra_width,
1698 p2 = ppar->pextra_widthp;
1699 ppar->SetPExtraType(ppar->pextra_type,
1700 p1.c_str(), p2.c_str());
1702 if ((par->pextra_type == PEXTRA_NONE) &&
1703 npar && (npar->pextra_type != PEXTRA_NONE)) {
1705 p1 = npar->pextra_width,
1706 p2 = npar->pextra_widthp;
1707 npar->SetPExtraType(npar->pextra_type,
1708 p1.c_str(), p2.c_str());
1714 // if the layout of a paragraph contains a manual label, the beginning of the
1715 // main body is the beginning of the second word. This is what the par-
1716 // function returns. If the layout does not contain a label, the main
1717 // body always starts with position 0. This differentiation is necessary,
1718 // because there cannot be a newline or a blank <= the beginning of the
1719 // main body in TeX.
1721 int LyXParagraph::BeginningOfMainBody() const
1723 if (FirstPhysicalPar() != this)
1726 // Unroll the first two cycles of the loop
1727 // and remember the previous character to
1728 // remove unnecessary GetChar() calls
1731 && GetChar(i) != LyXParagraph::META_NEWLINE
1734 char previous_char, temp;
1736 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1737 // Yes, this ^ is supposed to be "= " not "=="
1740 && previous_char != ' '
1741 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1743 previous_char = temp;
1748 if (i == 0 && i == size() &&
1749 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1750 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1751 ++i; /* the cursor should not jump
1752 * to the main body if there
1758 LyXParagraph * LyXParagraph::DepthHook(int deth)
1760 LyXParagraph * newpar = this;
1765 newpar = newpar->FirstPhysicalPar()->Previous();
1766 } while (newpar && newpar->GetDepth() > deth
1767 && newpar->footnoteflag == footnoteflag);
1770 if (Previous() || GetDepth())
1771 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1775 return newpar->FirstPhysicalPar();
1779 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1781 LyXParagraph const * newpar = this;
1786 newpar = newpar->FirstPhysicalPar()->Previous();
1787 } while (newpar && newpar->GetDepth() > deth
1788 && newpar->footnoteflag == footnoteflag);
1791 if (Previous() || GetDepth())
1792 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1796 return newpar->FirstPhysicalPar();
1800 int LyXParagraph::AutoDeleteInsets()
1802 vector<size_type> tmpvec;
1804 for (InsetList::iterator it = insetlist.begin();
1805 it != insetlist.end(); ++it) {
1806 if ((*it).inset && (*it).inset->AutoDelete()) {
1807 tmpvec.push_back((*it).pos);
1811 for (vector<size_type>::const_iterator cit = tmpvec.begin();
1812 cit != tmpvec.end(); ++cit) {
1819 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1821 InsetList::iterator it2 = insetlist.end();
1822 for (InsetList::iterator it = insetlist.begin();
1823 it != insetlist.end(); ++it) {
1824 if ((*it).pos >= pos) {
1825 if (it2 == insetlist.end() || (*it).pos < (*it2).pos)
1829 if (it2 != insetlist.end()) {
1831 return (*it2).inset;
1837 // returns -1 if inset not found
1838 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1841 for (InsetList::const_iterator cit = insetlist.begin();
1842 cit != insetlist.end(); ++cit) {
1843 if ((*cit).inset == inset) {
1847 // Think about footnotes.
1848 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1849 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1851 NextAfterFootnote()->GetPositionOfInset(inset);
1853 return text.size() + 1 + further;
1859 void LyXParagraph::readSimpleWholeFile(istream & is)
1865 InsertChar(text.size(), c);
1870 LyXParagraph * LyXParagraph::TeXOnePar(string & file, TexRow & texrow,
1871 string & foot, TexRow & foot_texrow,
1874 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1875 LyXParagraph * par = next;
1876 LyXLayout const & style =
1877 textclasslist.Style(current_view->buffer()->params.textclass,
1880 bool further_blank_line = false;
1882 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1884 if (start_of_appendix) {
1885 file += "\\appendix\n";
1889 if (tex_code_break_column && style.isCommand()){
1894 if (pagebreak_top) {
1895 file += "\\newpage";
1896 further_blank_line = true;
1898 if (added_space_top.kind() != VSpace::NONE) {
1899 file += added_space_top.asLatexCommand(current_view->buffer()->params);
1900 further_blank_line = true;
1904 file += "\\lyxline{\\" + getFont(0).latexSize() + '}';
1905 file += "\\vspace{-1\\parskip}";
1906 further_blank_line = true;
1909 if (further_blank_line){
1914 LyXDirection direction = getParDirection();
1915 LyXDirection global_direction =
1916 current_view->buffer()->params.getDocumentDirection();
1917 if (direction != global_direction) {
1918 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1919 file += "\\unsethebrew\n";
1921 file += "\\sethebrew\n";
1926 switch (style.latextype) {
1929 file += style.latexname();
1930 file += style.latexparam();
1932 case LATEX_ITEM_ENVIRONMENT:
1934 bibkey->Latex(file, false);
1938 case LATEX_LIST_ENVIRONMENT:
1945 bool need_par = SimpleTeXOnePar(file, texrow);
1947 // Spit out footnotes
1948 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1949 && par->footnoteflag != footnoteflag) {
1950 par = par->TeXFootnote(file, texrow,
1951 foot, foot_texrow, foot_count,
1953 par->SimpleTeXOnePar(file, texrow);
1957 // Make sure that \\par is done with the font of the last
1958 // character if this has another size as the default.
1959 // This is necessary because LaTeX (and LyX on the screen)
1960 // calculates the space between the baselines according
1961 // to this font. (Matthias)
1962 LyXFont font = getFont(Last()-1);
1964 if (style.resfont.size() != font.size()) {
1966 file += font.latexSize();
1970 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
1971 GetLayout()).isCommand()){
1972 if (style.resfont.size() != font.size()) {
1974 file += font.latexSize();
1978 } else if (style.resfont.size() != font.size()){
1979 file += "{\\" + font.latexSize() + " \\par}";
1982 if (direction != global_direction)
1983 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1984 file += "\\sethebrew";
1986 file += "\\unsethebrew";
1988 switch (style.latextype) {
1989 case LATEX_ITEM_ENVIRONMENT:
1990 case LATEX_LIST_ENVIRONMENT:
1991 if (par && (depth < par->depth)) {
1996 case LATEX_ENVIRONMENT:
1997 // if its the last paragraph of the current environment
1998 // skip it otherwise fall through
2000 && (par->layout != layout
2001 || par->depth != depth
2002 || par->pextra_type != pextra_type))
2005 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2006 && footnotekind != LyXParagraph::FOOTNOTE
2007 && footnotekind != LyXParagraph::MARGIN
2011 // don't insert this if we would be adding it
2012 // before or after a table in a float. This
2013 // little trick is needed in order to allow
2014 // use of tables in \subfigures or \subtables.
2020 further_blank_line = false;
2022 file += "\\lyxline{\\" + getFont(Last()-1).latexSize() + '}';
2023 further_blank_line = true;
2026 if (added_space_bottom.kind() != VSpace::NONE) {
2027 file += added_space_bottom.asLatexCommand(current_view->buffer()->params);
2028 further_blank_line = true;
2031 if (pagebreak_bottom) {
2032 file += "\\newpage";
2033 further_blank_line = true;
2036 if (further_blank_line){
2041 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2042 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2047 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2052 // This one spits out the text of the paragraph
2053 bool LyXParagraph::SimpleTeXOnePar(string & file, TexRow & texrow)
2055 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2058 return SimpleTeXOneTablePar(file, texrow);
2060 bool return_value = false;
2062 LyXLayout const & style =
2063 textclasslist.Style(current_view->buffer()->params.textclass,
2065 LyXFont basefont, last_font;
2067 // Maybe we have to create a optional argument.
2068 size_type main_body;
2069 if (style.labeltype != LABEL_MANUAL)
2072 main_body = BeginningOfMainBody();
2074 if (main_body > 0) {
2076 basefont = getFont(-2); // Get label font
2078 basefont = getFont(-1); // Get layout font
2086 if (style.isCommand()) {
2089 } else if (align != LYX_ALIGN_LAYOUT) {
2092 return_value = true;
2096 // Which font is currently active?
2097 LyXFont running_font = basefont;
2098 // Do we have an open font change?
2099 bool open_font = false;
2101 texrow.start(this, 0);
2103 for (size_type i = 0; i < size(); ++i) {
2105 // First char in paragraph or after label?
2106 if (i == main_body && !IsDummy()) {
2107 if (main_body > 0) {
2109 column += running_font.latexWriteEndChanges(file, basefont, basefont);
2112 basefont = getFont(-1); // Now use the layout font
2113 running_font = basefont;
2117 if (style.isCommand()) {
2120 } else if (align != LYX_ALIGN_LAYOUT) {
2123 return_value = true;
2127 file += "\\noindent ";
2131 case LYX_ALIGN_NONE:
2132 case LYX_ALIGN_BLOCK:
2133 case LYX_ALIGN_LAYOUT:
2134 case LYX_ALIGN_SPECIAL: break;
2135 case LYX_ALIGN_LEFT:
2136 file += "\\raggedright ";
2139 case LYX_ALIGN_RIGHT:
2140 file += "\\raggedleft ";
2143 case LYX_ALIGN_CENTER:
2144 file += "\\centering ";
2152 // Fully instantiated font
2153 LyXFont font = getFont(i);
2154 last_font = running_font;
2156 // Spaces at end of font change are simulated to be
2157 // outside font change, i.e. we write "\textXX{text} "
2158 // rather than "\textXX{text }". (Asger)
2159 if (open_font && c == ' ' && i <= size() - 2
2160 && !getFont(i+1).equalExceptLatex(running_font)
2161 && !getFont(i+1).equalExceptLatex(font)) {
2162 font = getFont(i + 1);
2164 // We end font definition before blanks
2165 if (!font.equalExceptLatex(running_font) && open_font) {
2166 column += running_font.latexWriteEndChanges(file,
2168 (i == main_body-1) ? basefont : font);
2169 running_font = basefont;
2173 // Blanks are printed before start of fontswitch
2175 // Do not print the separation of the optional argument
2176 if (i != main_body - 1) {
2177 SimpleTeXBlanks(file, texrow, i,
2178 column, font, style);
2182 // Do we need to change font?
2183 if (!font.equalExceptLatex(running_font)
2184 && i != main_body-1) {
2185 column += font.latexWriteStartChanges(file, basefont, last_font);
2186 running_font = font;
2190 if (c == LyXParagraph::META_NEWLINE) {
2191 // newlines are handled differently here than
2192 // the default in SimpleTeXSpecialChars().
2193 if (!style.newline_allowed
2194 || font.latex() == LyXFont::ON) {
2198 column += running_font.latexWriteEndChanges(file, basefont, basefont);
2201 basefont = getFont(-1);
2202 running_font = basefont;
2203 if (font.family() ==
2204 LyXFont::TYPEWRITER_FAMILY) {
2210 texrow.start(this, i + 1);
2213 SimpleTeXSpecialChars(file, texrow,
2214 font, running_font, basefont,
2215 open_font, style, i, column, c);
2219 // If we have an open font definition, we have to close it
2221 running_font.latexWriteEndChanges(file, basefont, basefont);
2224 // Needed if there is an optional argument but no contents.
2225 if (main_body > 0 && main_body == size()) {
2227 return_value = false;
2230 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2231 return return_value;
2235 // This one spits out the text of a table paragraph
2236 bool LyXParagraph::SimpleTeXOneTablePar(string & file, TexRow & texrow)
2238 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2240 bool return_value = false;
2242 LyXLayout const & style =
2243 textclasslist.Style(current_view->buffer()->params.textclass,
2247 if (!IsDummy()) { // it is dummy if it is in a float!!!
2248 if (style.isCommand()) {
2251 } else if (align != LYX_ALIGN_LAYOUT) {
2254 return_value = true;
2257 file += "\\noindent ";
2261 case LYX_ALIGN_NONE:
2262 case LYX_ALIGN_BLOCK:
2263 case LYX_ALIGN_LAYOUT:
2264 case LYX_ALIGN_SPECIAL: break;
2265 case LYX_ALIGN_LEFT:
2266 file += "\\raggedright ";
2269 case LYX_ALIGN_RIGHT:
2270 file += "\\raggedleft ";
2273 case LYX_ALIGN_CENTER:
2274 file += "\\centering ";
2280 LyXFont basefont = getFont(-1); // Get layout font
2281 // Which font is currently active?
2282 LyXFont running_font = basefont;
2284 // Do we have an open font change?
2285 bool open_font = false;
2286 int current_cell_number = -1;
2287 int tmp = table->TexEndOfCell(file, current_cell_number);
2288 for (; tmp > 0 ; --tmp)
2291 texrow.start(this, 0);
2293 for (size_type i = 0; i < size(); ++i) {
2294 char c = GetChar(i);
2295 if (table->IsContRow(current_cell_number + 1)) {
2296 if (c == LyXParagraph::META_NEWLINE)
2297 ++current_cell_number;
2302 // Fully instantiated font
2303 LyXFont font = getFont(i);
2304 last_font = running_font;
2306 // Spaces at end of font change are simulated to be
2307 // outside font change.
2308 // i.e. we write "\textXX{text} " rather than
2309 // "\textXX{text }". (Asger)
2310 if (open_font && c == ' ' && i <= size() - 2
2311 && getFont(i+1) != running_font && getFont(i+1) != font) {
2312 font = getFont(i+1);
2315 // We end font definition before blanks
2316 if (font != running_font && open_font) {
2317 column += running_font.latexWriteEndChanges(file,
2319 running_font = basefont;
2322 // Blanks are printed before start of fontswitch
2324 SimpleTeXBlanks(file, texrow, i, column, font, style);
2326 // Do we need to change font?
2327 if (font != running_font) {
2328 column += font.latexWriteStartChanges(file, basefont, last_font);
2329 running_font = font;
2332 // Do we need to turn on LaTeX mode?
2333 if (font.latex() != running_font.latex()) {
2334 if (font.latex() == LyXFont::ON
2335 && style.needprotect) {
2336 file += "\\protect ";
2340 if (c == LyXParagraph::META_NEWLINE) {
2341 // special case for inside a table
2342 // different from default case in
2343 // SimpleTeXSpecialChars()
2345 column += running_font
2346 .latexWriteEndChanges(file, basefont, basefont);
2349 basefont = getFont(-1);
2350 running_font = basefont;
2351 ++current_cell_number;
2352 if (table->CellHasContRow(current_cell_number) >= 0) {
2353 TeXContTableRows(file, i + 1,
2354 current_cell_number,
2357 // if this cell follow only ContRows till end don't
2358 // put the EndOfCell because it is put after the
2360 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2361 --current_cell_number;
2364 int tmp = table->TexEndOfCell(file,
2365 current_cell_number);
2368 } else if (tmp < 0) {
2374 texrow.start(this, i + 1);
2376 SimpleTeXSpecialChars(file, texrow,
2377 font, running_font, basefont,
2378 open_font, style, i, column, c);
2382 // If we have an open font definition, we have to close it
2384 running_font.latexWriteEndChanges(file, basefont, basefont);
2386 ++current_cell_number;
2387 tmp = table->TexEndOfCell(file, current_cell_number);
2388 for (; tmp > 0; --tmp)
2390 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2391 return return_value;
2395 // This one spits out the text off ContRows in tables
2396 bool LyXParagraph::TeXContTableRows(string & file,
2397 LyXParagraph::size_type i,
2398 int current_cell_number,
2399 int & column, TexRow & texrow)
2401 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2407 bool return_value = false;
2408 LyXLayout const & style =
2409 textclasslist.Style(current_view->buffer()->params.textclass,
2411 LyXFont basefont = getFont(-1); // Get layout font
2413 // Which font is currently active?
2414 LyXFont running_font = basefont;
2415 // Do we have an open font change?
2416 bool open_font = false;
2418 size_type lastpos = i;
2419 int cell = table->CellHasContRow(current_cell_number);
2420 ++current_cell_number;
2422 // first find the right position
2424 for (; (i < size()) && (current_cell_number<cell); ++i) {
2426 if (c == LyXParagraph::META_NEWLINE)
2427 ++current_cell_number;
2431 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2435 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2440 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2444 // Fully instantiated font
2445 LyXFont font = getFont(i);
2446 last_font = running_font;
2448 // Spaces at end of font change are simulated to
2449 // be outside font change. i.e. we write
2450 // "\textXX{text} " rather than "\textXX{text }".
2452 if (open_font && c == ' ' && i <= size() - 2
2453 && getFont(i + 1) != running_font
2454 && getFont(i + 1) != font) {
2455 font = getFont(i + 1);
2458 // We end font definition before blanks
2459 if (font != running_font && open_font) {
2460 column += running_font.latexWriteEndChanges(file, basefont, font);
2461 running_font = basefont;
2464 // Blanks are printed before start of fontswitch
2466 SimpleTeXBlanks(file, texrow, i,
2467 column, font, style);
2469 // Do we need to change font?
2470 if (font != running_font) {
2472 font.latexWriteStartChanges(file,
2473 basefont, last_font);
2474 running_font = font;
2477 // Do we need to turn on LaTeX mode?
2478 if (font.latex() != running_font.latex()) {
2479 if (font.latex() == LyXFont::ON
2480 && style.needprotect)
2482 file += "\\protect ";
2486 SimpleTeXSpecialChars(file, texrow, font,
2487 running_font, basefont,
2488 open_font, style, i, column, c);
2490 // If we have an open font definition, we have to close it
2492 running_font.latexWriteEndChanges(file, basefont, basefont);
2495 basefont = getFont(-1);
2496 running_font = basefont;
2497 cell = table->CellHasContRow(current_cell_number);
2499 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2500 return return_value;
2504 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2506 bool retval = false;
2508 case LyXParagraph::META_HFILL:
2509 sgml_string.clear();
2512 case LyXParagraph::META_PROTECTED_SEPARATOR:
2516 case LyXParagraph::META_NEWLINE:
2520 sgml_string = "&";
2523 sgml_string = "<";
2526 sgml_string = ">";
2529 sgml_string = "$";
2532 sgml_string = "#";
2535 sgml_string = "%";
2538 sgml_string = "[";
2541 sgml_string = "]";
2544 sgml_string = "{";
2547 sgml_string = "}";
2550 sgml_string = "˜";
2553 sgml_string = """;
2556 sgml_string = "\";
2562 case '\0': // Ignore :-)
2563 sgml_string.clear();
2573 void LyXParagraph::SimpleDocBookOneTablePar(string & file, string & extra,
2574 int & desc_on, int depth)
2577 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2579 LyXFont font1, font2;
2582 size_type main_body;
2583 string emph = "emphasis";
2584 bool emph_flag = false;
2586 LyXLayout const & style =
2587 textclasslist.Style(current_view->buffer()->params.textclass,
2590 if (style.labeltype != LABEL_MANUAL)
2593 main_body = BeginningOfMainBody();
2595 // Gets paragraph main font.
2597 font1 = style.labelfont;
2601 int char_line_count = depth;
2602 addNewlineAndDepth(file, depth);
2603 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2604 file += "<INFORMALTABLE>";
2605 addNewlineAndDepth(file, ++depth);
2607 int current_cell_number = -1;
2608 int tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
2610 // Parsing main loop.
2611 for (size_type i = 0; i < size(); ++i) {
2613 if (table->IsContRow(current_cell_number+1)) {
2614 if (c == LyXParagraph::META_NEWLINE)
2615 ++current_cell_number;
2620 // Fully instantiated font
2623 // Handle <emphasis> tag.
2624 if (font1.emph() != font2.emph() && i) {
2625 if (font2.emph() == LyXFont::ON) {
2626 file += "<emphasis>";
2628 } else if (emph_flag) {
2629 file += "</emphasis>";
2633 if (c == LyXParagraph::META_NEWLINE) {
2634 // We have only to control for emphasis open here!
2636 file += "</emphasis>";
2639 font1 = font2 = getFont(-1);
2640 ++current_cell_number;
2641 if (table->CellHasContRow(current_cell_number) >= 0) {
2642 DocBookContTableRows(file, extra, desc_on, i+1,
2643 current_cell_number,
2646 // if this cell follow only ContRows till end don't
2647 // put the EndOfCell because it is put after the
2649 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2650 --current_cell_number;
2653 tmp = table->DocBookEndOfCell(file,
2654 current_cell_number,
2659 } else if (c == LyXParagraph::META_INSET) {
2660 inset = GetInset(i);
2662 inset->DocBook(tmp_out);
2664 // This code needs some explanation:
2665 // Two insets are treated specially
2666 // label if it is the first element in a
2667 // command paragraph
2669 // graphics inside tables or figure floats
2671 // title (the equivalente in latex for this
2673 // and title should come first
2676 if(desc_on != 3 || i != 0) {
2677 if(tmp_out[0] == '@') {
2679 extra += frontStrip(tmp_out,
2682 file += frontStrip(tmp_out,
2687 } else if (font2.latex() == LyXFont::ON) {
2688 // "TeX"-Mode on == > SGML-Mode on.
2694 if (linuxDocConvertChar(c, sgml_string)
2695 && !style.free_spacing) {
2696 // in freespacing mode, spaces are
2697 // non-breaking characters
2702 file += "</term><listitem><para>";
2708 file += sgml_string;
2714 // Needed if there is an optional argument but no contents.
2715 if (main_body > 0 && main_body == size()) {
2720 file += "</emphasis>";
2723 ++current_cell_number;
2724 tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
2725 // Resets description flag correctly.
2728 // <term> not closed...
2732 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2733 file += "</INFORMALTABLE>";
2735 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2740 void LyXParagraph::DocBookContTableRows(string & file, string & extra,
2742 LyXParagraph::size_type i,
2743 int current_cell_number, int &column)
2748 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2753 string emph= "emphasis";
2754 bool emph_flag= false;
2755 int char_line_count= 0;
2757 LyXLayout const & style =
2758 textclasslist.Style(current_view->buffer()->params.textclass,
2761 size_type main_body;
2762 if (style.labeltype != LABEL_MANUAL)
2765 main_body = BeginningOfMainBody();
2767 // Gets paragraph main font.
2770 font1 = style.labelfont;
2774 size_type lastpos = i;
2775 int cell = table->CellHasContRow(current_cell_number);
2776 ++current_cell_number;
2778 // first find the right position
2780 for (; i < size() && current_cell_number < cell; ++i) {
2782 if (c == LyXParagraph::META_NEWLINE)
2783 ++current_cell_number;
2787 // I don't know how to handle this so I comment it
2788 // for the moment (Jug)
2789 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2790 // file += " \\\\\n";
2793 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2798 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2802 // Fully instantiated font
2805 // Handle <emphasis> tag.
2806 if (font1.emph() != font2.emph() && i) {
2807 if (font2.emph() == LyXFont::ON) {
2808 file += "<emphasis>";
2810 } else if (emph_flag) {
2811 file += "</emphasis>";
2815 if (c == LyXParagraph::META_INSET) {
2816 inset = GetInset(i);
2818 inset->DocBook(tmp_out);
2820 // This code needs some explanation:
2821 // Two insets are treated specially
2822 // label if it is the first element in a
2823 // command paragraph
2825 // graphics inside tables or figure floats
2826 // can't go on title (the equivalente in
2827 // latex for this case is caption and title
2828 // should come first
2831 if(desc_on != 3 || i != 0) {
2832 if(tmp_out[0] == '@') {
2834 extra += frontStrip(tmp_out, '@');
2836 file += frontStrip(tmp_out, '@');
2840 } else if (font2.latex() == LyXFont::ON) {
2841 // "TeX"-Mode on == > SGML-Mode on.
2847 if (linuxDocConvertChar(c, sgml_string)
2848 && !style.free_spacing) {
2849 // in freespacing mode, spaces are
2850 // non-breaking characters
2855 file += "</term><listitem><para>";
2861 file += sgml_string;
2865 // we have only to control for emphasis open here!
2867 file += "</emphasis>";
2870 font1 = font2 = getFont(-1);
2871 cell = table->CellHasContRow(current_cell_number);
2873 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
2877 void LyXParagraph::SimpleTeXBlanks(string & file, TexRow & texrow,
2878 LyXParagraph::size_type const i,
2879 int & column, LyXFont const & font,
2880 LyXLayout const & style)
2882 if (column > tex_code_break_column
2884 && GetChar(i - 1) != ' '
2886 // In LaTeX mode, we don't want to
2887 // break lines since some commands
2889 && ! (font.latex() == LyXFont::ON)
2890 // same in FreeSpacing mode
2891 && !style.free_spacing
2892 // In typewriter mode, we want to avoid
2893 // ! . ? : at the end of a line
2894 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
2895 && (GetChar(i-1) == '.'
2896 || GetChar(i-1) == '?'
2897 || GetChar(i-1) == ':'
2898 || GetChar(i-1) == '!'))) {
2899 if (tex_code_break_column == 0) {
2900 // in batchmode we need LaTeX to still
2901 // see it as a space not as an extra '\n'
2907 texrow.start(this, i+1);
2909 } else if (font.latex() == LyXFont::OFF) {
2910 if (style.free_spacing) {
2919 void LyXParagraph::SimpleTeXSpecialChars(string & file, TexRow & texrow,
2921 LyXFont & running_font,
2924 LyXLayout const & style,
2925 LyXParagraph::size_type & i,
2926 int & column, char const c)
2928 // Two major modes: LaTeX or plain
2929 // Handle here those cases common to both modes
2930 // and then split to handle the two modes separately.
2932 case LyXParagraph::META_INSET: {
2933 Inset * inset = GetInset(i);
2936 int len = file.length();
2937 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
2938 || inset->LyxCode() == Inset::MATH_CODE
2939 || inset->LyxCode() == Inset::URL_CODE)
2940 && running_font.getFontDirection()
2941 == LYX_DIR_RIGHT_TO_LEFT) {
2945 int tmp = inset->Latex(file, style.isCommand());
2952 column += file.length() - len;
2961 case LyXParagraph::META_NEWLINE:
2963 column += running_font.latexWriteEndChanges(file,
2964 basefont, basefont);
2967 basefont = getFont(-1);
2968 running_font = basefont;
2971 case LyXParagraph::META_HFILL:
2972 file += "\\hfill{}";
2977 // And now for the special cases within each mode
2978 // Are we in LaTeX mode?
2979 if (font.latex() == LyXFont::ON) {
2980 // at present we only have one option
2981 // but I'll leave it as a switch statement
2982 // so its simpler to extend. (ARRae)
2985 case LyXParagraph::META_PROTECTED_SEPARATOR:
2990 // make sure that we will not print
2991 // error generating chars to the tex
2992 // file. This test would not be needed
2993 // if it were done in the buffer
3001 // Plain mode (i.e. not LaTeX)
3004 case LyXParagraph::META_PROTECTED_SEPARATOR:
3009 file += "\\textbackslash{}";
3013 case '°': case '±': case '²': case '³':
3014 case '×': case '÷': case '¹': case 'ª':
3015 case 'º': case '¬': case 'µ':
3016 if (current_view->buffer()->params.inputenc == "latin1") {
3017 file += "\\ensuremath{";
3026 case '|': case '<': case '>':
3027 // In T1 encoding, these characters exist
3028 if (lyxrc->fontenc == "T1") {
3030 //... but we should avoid ligatures
3031 if ((c == '>' || c == '<')
3033 && GetChar(i+1) == c){
3034 file += "\\textcompwordmark{}";
3039 // Typewriter font also has them
3040 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3044 // Otherwise, we use what LaTeX
3048 file += "\\textless{}";
3052 file += "\\textgreater{}";
3056 file += "\\textbar{}";
3062 case '-': // "--" in Typewriter mode -> "-{}-"
3064 && GetChar(i + 1) == '-'
3065 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3074 file += "\\char`\\\"{}";
3079 if (current_view->buffer()->params.inputenc == "default") {
3080 file += "\\pounds{}";
3088 case '%': case '#': case '{':
3096 file += "\\textasciitilde{}";
3101 file += "\\textasciicircum{}";
3105 case '*': case '[': case ']':
3106 // avoid being mistaken for optional arguments
3114 // Blanks are printed before font switching.
3115 // Sure? I am not! (try nice-latex)
3116 // I am sure it's correct. LyX might be smarter
3117 // in the future, but for now, nothing wrong is
3122 /* idea for labels --- begin*/
3126 && font.family() != LyXFont::TYPEWRITER_FAMILY
3127 && GetChar(i + 1) == 'y'
3128 && GetChar(i + 2) == 'X') {
3136 && font.family() != LyXFont::TYPEWRITER_FAMILY
3137 && GetChar(i + 1) == 'e'
3138 && GetChar(i + 2) == 'X') {
3143 // Check for "LaTeX2e"
3146 && font.family() != LyXFont::TYPEWRITER_FAMILY
3147 && GetChar(i + 1) == 'a'
3148 && GetChar(i + 2) == 'T'
3149 && GetChar(i + 3) == 'e'
3150 && GetChar(i + 4) == 'X'
3151 && GetChar(i + 5) == '2'
3152 && GetChar(i + 6) == 'e') {
3153 file += "\\LaTeXe{}";
3157 // Check for "LaTeX"
3160 && font.family() != LyXFont::TYPEWRITER_FAMILY
3161 && GetChar(i + 1) == 'a'
3162 && GetChar(i + 2) == 'T'
3163 && GetChar(i + 3) == 'e'
3164 && GetChar(i + 4) == 'X') {
3165 file += "\\LaTeX{}";
3168 /* idea for labels --- end*/
3169 } else if (c != '\0') {
3180 bool LyXParagraph::RoffContTableRows(ostream & os,
3181 LyXParagraph::size_type i,
3187 LyXFont font1(LyXFont::ALL_INHERIT);
3192 string fname2 = TmpFileName(string(), "RAT2");
3194 int cell = table->CellHasContRow(actcell);
3197 // first find the right position
3199 for (; i < size() && actcell < cell; ++i) {
3201 if (c == LyXParagraph::META_NEWLINE)
3206 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3209 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3211 font2 = GetFontSettings(i);
3212 if (font1.latex() != font2.latex()) {
3213 if (font2.latex() != LyXFont::OFF)
3218 case LyXParagraph::META_INSET:
3219 if ((inset = GetInset(i))) {
3222 stringstream ss(ios::in | ios::out);
3223 inset->Latex(ss, -1);
3235 inset->Latex(ss, -1);
3248 fstream fs(fname2.c_str(),
3251 WriteAlert(_("LYX_ERROR:"),
3252 _("Cannot open temporary file:"),
3256 inset->Latex(fs, -1);
3270 case LyXParagraph::META_NEWLINE:
3272 case LyXParagraph::META_HFILL:
3275 case LyXParagraph::META_PROTECTED_SEPARATOR:
3285 lyxerr.debug() << "RoffAsciiTable: "
3286 "NULL char in structure."
3291 cell = table->CellHasContRow(actcell);
3298 LyXParagraph * LyXParagraph::TeXDeeper(string & file, TexRow & texrow,
3299 string & foot, TexRow & foot_texrow,
3302 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3303 LyXParagraph * par = this;
3305 while (par && par->depth == depth) {
3307 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3308 if (textclasslist.Style(current_view->buffer()->params.textclass,
3309 par->layout).isEnvironment()
3310 || par->pextra_type != PEXTRA_NONE)
3312 par = par->TeXEnvironment(file, texrow,
3316 par = par->TeXOnePar(file, texrow,
3321 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3327 LyXParagraph * LyXParagraph::TeXEnvironment(string & file, TexRow & texrow,
3329 TexRow & foot_texrow,
3332 bool eindent_open = false;
3333 bool foot_this_level = false;
3334 // flags when footnotetext should be appended to file.
3335 static bool minipage_open = false;
3336 static int minipage_open_depth = 0;
3337 char par_sep = current_view->buffer()->params.paragraph_separation;
3339 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3341 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3343 LyXLayout const & style =
3344 textclasslist.Style(current_view->buffer()->params.textclass,
3347 if (pextra_type == PEXTRA_INDENT) {
3348 if (!pextra_width.empty()) {
3349 file += "\\begin{LyXParagraphIndent}{"
3350 + pextra_width + "}\n";
3352 //float ib = atof(pextra_widthp.c_str())/100;
3353 // string can't handle floats at present (971109)
3354 // so I'll do a conversion by hand knowing that
3355 // the limits are 0.0 to 1.0. ARRae.
3356 file += "\\begin{LyXParagraphIndent}{";
3357 switch (pextra_widthp.length()) {
3363 file += pextra_widthp;
3367 file += pextra_widthp;
3369 file += "\\columnwidth}\n";
3372 eindent_open = true;
3374 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3375 if (pextra_hfill && Previous() &&
3376 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3377 file += "\\hfill{}\n";
3380 if (par_sep == BufferParams::PARSEP_INDENT) {
3381 file += "{\\setlength\\parindent{0pt}\n";
3384 file += "\\begin{minipage}";
3385 switch(pextra_alignment) {
3386 case MINIPAGE_ALIGN_TOP:
3389 case MINIPAGE_ALIGN_MIDDLE:
3392 case MINIPAGE_ALIGN_BOTTOM:
3396 if (!pextra_width.empty()) {
3398 file += pextra_width + "}\n";
3400 //float ib = atof(par->pextra_width.c_str())/100;
3401 // string can't handle floats at present
3402 // so I'll do a conversion by hand knowing that
3403 // the limits are 0.0 to 1.0. ARRae.
3405 switch (pextra_widthp.length()) {
3411 file += pextra_widthp;
3415 file += pextra_widthp;
3417 file += "\\columnwidth}\n";
3420 if (par_sep == BufferParams::PARSEP_INDENT) {
3421 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3424 minipage_open = true;
3425 minipage_open_depth = depth;
3428 #ifdef WITH_WARNINGS
3429 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3430 //I disabled it because it breaks when lists span on several
3433 if (style.isEnvironment()){
3434 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3435 #ifdef FANCY_FOOTNOTE_CODE
3436 if (foot_count < 0) {
3437 // flag that footnote[mark][text] should be
3438 // used for any footnotes from now on
3440 foot_this_level = true;
3443 file += "\\begin{" + style.latexname() + "}{"
3444 + labelwidthstring + "}\n";
3445 } else if (style.labeltype == LABEL_BIBLIO) {
3447 file += "\\begin{" + style.latexname() + "}{"
3448 + bibitemWidthest(current_view->painter())
3450 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3451 #ifdef FANCY_FOOTNOTE_CODE
3452 if (foot_count < 0) {
3453 // flag that footnote[mark][text] should be
3454 // used for any footnotes from now on
3456 foot_this_level = true;
3459 file += "\\begin{" + style.latexname() + '}'
3460 + style.latexparam() + '\n';
3462 file += "\\begin{" + style.latexname() + '}'
3463 + style.latexparam() + '\n';
3466 LyXParagraph * par = this;
3468 par = par->TeXOnePar(file, texrow,
3469 foot, foot_texrow, foot_count);
3471 if (minipage_open && par && !style.isEnvironment() &&
3472 (par->pextra_type == PEXTRA_MINIPAGE) &&
3473 par->pextra_start_minipage) {
3474 file += "\\end{minipage}\n";
3476 if (par_sep == BufferParams::PARSEP_INDENT) {
3480 minipage_open = false;
3482 if (par && par->depth > depth) {
3483 if (textclasslist.Style(current_view->buffer()->params.textclass,
3484 par->layout).isParagraph()
3486 && !suffixIs(file, "\n\n")) {
3487 // There should be at least one '\n' already
3488 // but we need there to be two for Standard
3489 // paragraphs that are depth-increment'ed to be
3490 // output correctly. However, tables can
3491 // also be paragraphs so don't adjust them.
3496 par = par->TeXDeeper(file, texrow,
3497 foot, foot_texrow, foot_count);
3499 if (par && par->layout == layout && par->depth == depth &&
3500 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3501 if (par->pextra_hfill && par->Previous() &&
3502 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3503 file += "\\hfill{}\n";
3506 if (par_sep == BufferParams::PARSEP_INDENT) {
3507 file += "{\\setlength\\parindent{0pt}\n";
3510 file += "\\begin{minipage}";
3511 switch(par->pextra_alignment) {
3512 case MINIPAGE_ALIGN_TOP:
3515 case MINIPAGE_ALIGN_MIDDLE:
3518 case MINIPAGE_ALIGN_BOTTOM:
3522 if (!par->pextra_width.empty()) {
3524 file += par->pextra_width;
3527 //float ib = atof(par->pextra_widthp.c_str())/100;
3528 // string can't handle floats at present
3529 // so I'll do a conversion by hand knowing that
3530 // the limits are 0.0 to 1.0. ARRae.
3532 switch (par->pextra_widthp.length()) {
3538 file += par->pextra_widthp;
3542 file += par->pextra_widthp;
3544 file += "\\columnwidth}\n";
3547 if (par_sep == BufferParams::PARSEP_INDENT) {
3548 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3551 minipage_open = true;
3552 minipage_open_depth = par->depth;
3555 && par->layout == layout
3556 && par->depth == depth
3557 && par->pextra_type == pextra_type);
3559 if (style.isEnvironment()) {
3560 file += "\\end{" + style.latexname() + '}';
3561 // maybe this should go after the minipage closes?
3562 if (foot_this_level) {
3563 if (foot_count >= 1) {
3564 if (foot_count > 1) {
3565 file += "\\addtocounter{footnote}{-";
3566 file += tostr(foot_count - 1);
3570 texrow += foot_texrow;
3572 foot_texrow.reset();
3577 if (minipage_open && (minipage_open_depth == depth) &&
3578 (!par || par->pextra_start_minipage ||
3579 par->pextra_type != PEXTRA_MINIPAGE)) {
3580 file += "\\end{minipage}\n";
3582 if (par_sep == BufferParams::PARSEP_INDENT) {
3586 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3587 file += "\\medskip\n\n";
3591 minipage_open = false;
3594 file += "\\end{LyXParagraphIndent}\n";
3597 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3598 && par->pextra_hfill)) {
3602 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3603 return par; // ale970302
3607 LyXParagraph * LyXParagraph::TeXFootnote(string & file, TexRow & texrow,
3608 string & foot, TexRow & foot_texrow,
3610 LyXDirection par_direction)
3612 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3613 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3614 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3615 "No footnote!" << endl;
3617 LyXParagraph * par = this;
3618 LyXLayout const & style =
3619 textclasslist.Style(current_view->buffer()->params.textclass,
3620 previous->GetLayout());
3622 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3623 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3624 "Float other than footnote in command"
3625 " with moving argument is illegal" << endl;
3628 if (footnotekind != LyXParagraph::FOOTNOTE
3629 && footnotekind != LyXParagraph::MARGIN
3631 && !suffixIs(file, '\n')) {
3632 // we need to ensure that real floats like tables and figures
3633 // have their \begin{} on a new line otherwise we can get
3634 // incorrect results when using the endfloat.sty package
3635 // especially if two floats follow one another. ARRae 981022
3636 // NOTE: if the file is length 0 it must have just been
3637 // written out so we assume it ended with a '\n'
3642 BufferParams * params = ¤t_view->buffer()->params;
3643 bool footer_in_body = true;
3644 switch (footnotekind) {
3645 case LyXParagraph::FOOTNOTE:
3646 if (style.intitle) {
3647 file += "\\thanks{\n";
3648 footer_in_body = false;
3650 if (foot_count == -1) {
3651 // we're at depth 0 so we can use:
3652 file += "\\footnote{%\n";
3653 footer_in_body = false;
3655 file += "\\footnotemark{}%\n";
3657 // we only need this when there are
3658 // multiple footnotes
3659 foot += "\\stepcounter{footnote}";
3661 foot += "\\footnotetext{%\n";
3662 foot_texrow.start(this, 0);
3663 foot_texrow.newline();
3668 case LyXParagraph::MARGIN:
3669 file += "\\marginpar{\n";
3671 case LyXParagraph::FIG:
3672 if (pextra_type == PEXTRA_FLOATFLT
3673 && (!pextra_width.empty()
3674 || !pextra_widthp.empty())) {
3676 if (!pextra_width.empty())
3677 sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
3678 pextra_width.c_str());
3681 "\\begin{floatingfigure}{%f\\textwidth}\n",
3682 atoi(pextra_widthp.c_str())/100.0);
3685 file += "\\begin{figure}";
3686 if (!params->float_placement.empty()) {
3688 file += params->float_placement;
3695 case LyXParagraph::TAB:
3696 file += "\\begin{table}";
3697 if (!params->float_placement.empty()) {
3699 file += params->float_placement;
3705 case LyXParagraph::WIDE_FIG:
3706 file += "\\begin{figure*}";
3707 if (!params->float_placement.empty()) {
3709 file += params->float_placement;
3715 case LyXParagraph::WIDE_TAB:
3716 file += "\\begin{table*}";
3717 if (!params->float_placement.empty()) {
3719 file += params->float_placement;
3725 case LyXParagraph::ALGORITHM:
3726 file += "\\begin{algorithm}\n";
3732 LyXDirection direction = getParDirection();
3733 if (direction != par_direction) {
3734 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3735 file += "\\unsethebrew\n";
3737 file += "\\sethebrew\n";
3741 if (footnotekind != LyXParagraph::FOOTNOTE
3742 || !footer_in_body) {
3743 // Process text for all floats except footnotes in body
3745 LyXLayout const & style =
3747 .Style(current_view->buffer()->params
3751 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3753 if (style.isEnvironment()
3754 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3755 // Allows the use of minipages within float
3756 // environments. Shouldn't be circular because
3757 // we don't support footnotes inside
3758 // floats (yet). ARRae
3759 par = par->TeXEnvironment(file, texrow,
3763 par = par->TeXOnePar(file, texrow,
3768 if (par && !par->IsDummy() && par->depth > depth) {
3769 par = par->TeXDeeper(file, texrow,
3773 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3775 // process footnotes > depth 0 or in environments separately
3776 // NOTE: Currently don't support footnotes within footnotes
3777 // even though that is possible using the \footnotemark
3779 TexRow dummy_texrow;
3780 int dummy_count = 0;
3782 LyXLayout const & style =
3784 .Style(current_view->buffer()->params
3788 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3790 if (style.isEnvironment()
3791 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3792 // Allows the use of minipages within float
3793 // environments. Shouldn't be circular because
3794 // we don't support footnotes inside
3795 // floats (yet). ARRae
3796 par = par->TeXEnvironment(foot, foot_texrow,
3797 dummy, dummy_texrow,
3800 par = par->TeXOnePar(foot, foot_texrow,
3801 dummy, dummy_texrow,
3805 if (par && !par->IsDummy() && par->depth > depth) {
3806 par = par->TeXDeeper(foot, foot_texrow,
3807 dummy, dummy_texrow,
3811 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3813 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3814 "Footnote in a Footnote -- not supported"
3819 switch (footnotekind) {
3820 case LyXParagraph::FOOTNOTE:
3821 if (footer_in_body) {
3822 // This helps tell which of the multiple
3823 // footnotetexts an error was in.
3825 foot_texrow.newline();
3830 case LyXParagraph::MARGIN:
3833 case LyXParagraph::FIG:
3834 if (pextra_type == PEXTRA_FLOATFLT
3835 && (!pextra_width.empty()
3836 || !pextra_widthp.empty()))
3837 file += "\\end{floatingfigure}";
3839 file += "\\end{figure}";
3841 case LyXParagraph::TAB:
3842 file += "\\end{table}";
3844 case LyXParagraph::WIDE_FIG:
3845 file += "\\end{figure*}";
3847 case LyXParagraph::WIDE_TAB:
3848 file += "\\end{table*}";
3850 case LyXParagraph::ALGORITHM:
3851 file += "\\end{algorithm}";
3855 if (footnotekind != LyXParagraph::FOOTNOTE
3856 && footnotekind != LyXParagraph::MARGIN) {
3857 // we need to ensure that real floats like tables and figures
3858 // have their \end{} on a line of their own otherwise we can
3859 // get incorrect results when using the endfloat.sty package.
3864 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
3869 void LyXParagraph::SetPExtraType(int type, char const * width,
3870 char const * widthp)
3873 pextra_width = width;
3874 pextra_widthp = widthp;
3876 if (textclasslist.Style(current_view->buffer()->params.textclass,
3877 layout).isEnvironment()) {
3882 while (par && (par->layout == layout)
3883 && (par->depth == depth)) {
3885 par = par->Previous();
3887 par = par->FirstPhysicalPar();
3888 while (par && par->depth > depth) {
3889 par = par->Previous();
3891 par = par->FirstPhysicalPar();
3895 while (par && (par->layout == layout)
3896 && (par->depth == depth)) {
3897 par->pextra_type = type;
3898 par->pextra_width = width;
3899 par->pextra_widthp = widthp;
3900 par = par->NextAfterFootnote();
3901 if (par && (par->depth > depth))
3902 par->SetPExtraType(type, width, widthp);
3903 while (par && ((par->depth > depth) || par->IsDummy()))
3904 par = par->NextAfterFootnote();
3910 void LyXParagraph::UnsetPExtraType()
3912 if (pextra_type == PEXTRA_NONE)
3915 pextra_type = PEXTRA_NONE;
3916 pextra_width.clear();
3917 pextra_widthp.clear();
3919 if (textclasslist.Style(current_view->buffer()->params.textclass,
3920 layout).isEnvironment()) {
3925 while (par && (par->layout == layout)
3926 && (par->depth == depth)) {
3928 par = par->Previous();
3930 par = par->FirstPhysicalPar();
3931 while (par && par->depth > depth) {
3932 par = par->Previous();
3934 par = par->FirstPhysicalPar();
3938 while (par && (par->layout == layout)
3939 && (par->depth == depth)) {
3940 par->pextra_type = PEXTRA_NONE;
3941 par->pextra_width.clear();
3942 par->pextra_widthp.clear();
3943 par = par->NextAfterFootnote();
3944 if (par && (par->depth > depth))
3945 par->UnsetPExtraType();
3946 while (par && ((par->depth > depth) || par->IsDummy()))
3947 par = par->NextAfterFootnote();
3953 bool LyXParagraph::IsHfill(size_type pos) const
3955 return IsHfillChar(GetChar(pos));
3959 bool LyXParagraph::IsInset(size_type pos) const
3961 return IsInsetChar(GetChar(pos));
3965 bool LyXParagraph::IsFloat(size_type pos) const
3967 return IsFloatChar(GetChar(pos));
3971 bool LyXParagraph::IsNewline(size_type pos) const
3975 tmp = IsNewlineChar(GetChar(pos));
3980 bool LyXParagraph::IsSeparator(size_type pos) const
3982 return IsSeparatorChar(GetChar(pos));
3986 bool LyXParagraph::IsLineSeparator(size_type pos) const
3988 return IsLineSeparatorChar(GetChar(pos));
3992 bool LyXParagraph::IsKomma(size_type pos) const
3994 return IsKommaChar(GetChar(pos));
3998 /// Used by the spellchecker
3999 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4001 unsigned char c = GetChar(pos);
4002 if (IsLetterChar(c))
4004 // '\0' is not a letter, allthough every string contains "" (below)
4007 // We want to pass the ' and escape chars to ispell
4008 string extra = lyxrc->isp_esc_chars + '\'';
4012 return contains(extra, ch);
4016 bool LyXParagraph::IsWord(size_type pos ) const
4018 return IsWordChar(GetChar(pos)) ;
4022 LyXDirection LyXParagraph::getParDirection() const
4024 if (!lyxrc->rtl_support || table)
4025 return LYX_DIR_LEFT_TO_RIGHT;
4028 return (getFont(0).direction() == LyXFont::RTL_DIR)
4029 ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT;
4031 return current_view->buffer()->params.getDocumentDirection();
4036 LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
4038 if (!lyxrc->rtl_support)
4039 return LYX_DIR_LEFT_TO_RIGHT;
4041 LyXDirection direction = getFont(pos).getFontDirection();
4042 if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
4043 && !IsLineSeparator(pos + 1)
4044 && !(table && IsNewline(pos + 1))
4045 && (getFont(pos - 1).getFontDirection() != direction
4046 || getFont(pos + 1).getFontDirection() != direction))
4047 return getParDirection();