-void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
- LyXParagraph::size_type const i,
- int & column, LyXFont const & font,
- LyXLayout const & style)
-{
- if (column > tex_code_break_column
- && i
- && GetChar(i - 1) != ' '
- && (i < size() - 1)
- // In LaTeX mode, we don't want to
- // break lines since some commands
- // do not like this
- && ! (font.latex() == LyXFont::ON)
- // same in FreeSpacing mode
- && !style.free_spacing
- // In typewriter mode, we want to avoid
- // ! . ? : at the end of a line
- && !(font.family() == LyXFont::TYPEWRITER_FAMILY
- && (GetChar(i-1) == '.'
- || GetChar(i-1) == '?'
- || GetChar(i-1) == ':'
- || GetChar(i-1) == '!'))) {
- if (tex_code_break_column == 0) {
- // in batchmode we need LaTeX to still
- // see it as a space not as an extra '\n'
- os << " %\n";
- } else {
- os << '\n';
- }
- texrow.newline();
- texrow.start(this, i + 1);
- column = 0;
- } else if (font.latex() == LyXFont::OFF) {
- if (style.free_spacing) {
- os << '~';
- } else {
- os << ' ';
- }
- }
-}
-
-
-void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
- BufferParams const & bparams,
- ostream & os, TexRow & texrow,
- bool moving_arg,
- LyXFont & font,
- LyXFont & running_font,
- LyXFont & basefont,
- bool & open_font,
- LyXLayout const & style,
- LyXParagraph::size_type & i,
- int & column,
- LyXParagraph::value_type const c)
-{
- // Two major modes: LaTeX or plain
- // Handle here those cases common to both modes
- // and then split to handle the two modes separately.
- switch (c) {
- case LyXParagraph::META_INSET: {
- Inset * inset = GetInset(i);
- if (inset) {
- bool close = false;
- int const len = os.tellp();
- if ((inset->LyxCode() == Inset::GRAPHICS_CODE
- || inset->LyxCode() == Inset::MATH_CODE
- || inset->LyxCode() == Inset::URL_CODE)
- && running_font.isRightToLeft()) {
- os << "\\L{";
- close = true;
- }
-
- int tmp = inset->Latex(buf, os, moving_arg,
- style.free_spacing);
-
- if (close)
- os << "}";
-
- if (tmp) {
- column = 0;
- } else {
- column += os.tellp() - len;
- }
- for (; tmp--;) {
- texrow.newline();
- }
- }
- }
- break;
-
- case LyXParagraph::META_NEWLINE:
- if (open_font) {
- column += running_font.latexWriteEndChanges(os,
- basefont,
- basefont);
- open_font = false;
- }
- basefont = getFont(bparams, -1);
- running_font = basefont;
- break;
-
- case LyXParagraph::META_HFILL:
- os << "\\hfill{}";
- column += 7;
- break;
-
- default:
- // And now for the special cases within each mode
- // Are we in LaTeX mode?
- if (font.latex() == LyXFont::ON) {
- // at present we only have one option
- // but I'll leave it as a switch statement
- // so its simpler to extend. (ARRae)
- switch (c) {
- default:
- // make sure that we will not print
- // error generating chars to the tex
- // file. This test would not be needed
- // if it were done in the buffer
- // itself.
- if (c != '\0') {
- os << c;
- }
- break;
- }
- } else {
- // Plain mode (i.e. not LaTeX)
- switch (c) {
- case '\\':
- os << "\\textbackslash{}";
- column += 15;
- break;
-
- case '°': case '±': case '²': case '³':
- case '×': case '÷': case '¹': case 'ª':
- case 'º': case '¬': case 'µ':
- if (bparams.inputenc == "latin1" ||
- (bparams.inputenc == "auto" &&
- font.language()->encoding()->LatexName()
- == "latin1")) {
- os << "\\ensuremath{"
- << c
- << '}';
- column += 13;
- } else {
- os << c;
- }
- break;
-
- case '|': case '<': case '>':
- // In T1 encoding, these characters exist
- if (lyxrc.fontenc == "T1") {
- os << c;
- //... but we should avoid ligatures
- if ((c == '>' || c == '<')
- && i <= size() - 2
- && GetChar(i + 1) == c) {
- //os << "\\textcompwordmark{}";
- // Jean-Marc, have a look at
- // this. IÂ think this works
- // equally well:
- os << "\\,{}";
- // Lgb
- column += 19;
- }
- break;
- }
- // Typewriter font also has them
- if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
- os << c;
- break;
- }
- // Otherwise, we use what LaTeX
- // provides us.
- switch (c) {
- case '<':
- os << "\\textless{}";
- column += 10;
- break;
- case '>':
- os << "\\textgreater{}";
- column += 13;
- break;
- case '|':
- os << "\\textbar{}";
- column += 9;
- break;
- }
- break;
-
- case '-': // "--" in Typewriter mode -> "-{}-"
- if (i <= size() - 2
- && GetChar(i + 1) == '-'
- && font.family() == LyXFont::TYPEWRITER_FAMILY) {
- os << "-{}";
- column += 2;
- } else {
- os << '-';
- }
- break;
-
- case '\"':
- os << "\\char`\\\"{}";
- column += 9;
- break;
-
- case '£':
- if (bparams.inputenc == "default") {
- os << "\\pounds{}";
- column += 8;
- } else {
- os << c;
- }
- break;
-
- case '$': case '&':
- case '%': case '#': case '{':
- case '}': case '_':
- os << '\\' << c;
- column += 1;
- break;
-
- case '~':
- os << "\\textasciitilde{}";
- column += 16;
- break;
-
- case '^':
- os << "\\textasciicircum{}";
- column += 17;
- break;
-
- case '*': case '[': case ']':
- // avoid being mistaken for optional arguments
- os << '{' << c << '}';
- column += 2;
- break;
-
- case ' ':
- // Blanks are printed before font switching.
- // Sure? I am not! (try nice-latex)
- // I am sure it's correct. LyX might be smarter
- // in the future, but for now, nothing wrong is
- // written. (Asger)
- break;
-
- default:
- /* idea for labels --- begin*/
- // Check for "LyX"
- if (c == 'L'
- && i <= size() - 3
- && font.family() != LyXFont::TYPEWRITER_FAMILY
- && GetChar(i + 1) == 'y'
- && GetChar(i + 2) == 'X') {
- os << "\\LyX{}";
- i += 2;
- column += 5;
- }
- // Check for "TeX"
- else if (c == 'T'
- && i <= size() - 3
- && font.family() != LyXFont::TYPEWRITER_FAMILY
- && GetChar(i + 1) == 'e'
- && GetChar(i + 2) == 'X') {
- os << "\\TeX{}";
- i += 2;
- column += 5;
- }
- // Check for "LaTeX2e"
- else if (c == 'L'
- && i <= size() - 7
- && font.family() != LyXFont::TYPEWRITER_FAMILY
- && GetChar(i + 1) == 'a'
- && GetChar(i + 2) == 'T'
- && GetChar(i + 3) == 'e'
- && GetChar(i + 4) == 'X'
- && GetChar(i + 5) == '2'
- && GetChar(i + 6) == 'e') {
- os << "\\LaTeXe{}";
- i += 6;
- column += 8;
- }
- // Check for "LaTeX"
- else if (c == 'L'
- && i <= size() - 5
- && font.family() != LyXFont::TYPEWRITER_FAMILY
- && GetChar(i + 1) == 'a'
- && GetChar(i + 2) == 'T'
- && GetChar(i + 3) == 'e'
- && GetChar(i + 4) == 'X') {
- os << "\\LaTeX{}";
- i += 4;
- column += 7;
- /* idea for labels --- end*/
- } else if (c != '\0') {
- os << c;
- }
- break;
- }
- }
- }
-}
-
-
-LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
- BufferParams const & bparams,
- ostream & os, TexRow & texrow
-#ifndef NEW_INSETS
- ,ostream & foot,
- TexRow & foot_texrow,
- int & foot_count
-#endif
- )
-{
- lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
- LyXParagraph * par = this;
-
- while (par &&
- (par->depth == depth)
-#ifndef NEW_INSETS
- && (par->footnoteflag == footnoteflag)
-#endif
- ) {
-#ifndef NEW_INSETS
- if (par->IsDummy())
- lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
-#endif
- if (textclasslist.Style(bparams.textclass,
- par->layout).isEnvironment()
- || par->pextra_type != PEXTRA_NONE) {
- par = par->TeXEnvironment(buf, bparams,
- os, texrow
-#ifndef NEW_INSETS
- ,foot, foot_texrow,
- foot_count
-#endif
- );
- } else {
- par = par->TeXOnePar(buf, bparams,
- os, texrow, false
-#ifndef NEW_INSETS
- ,
- foot, foot_texrow,
- foot_count
-#endif
- );
- }
- }
- lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
-
- return par;
-}
-
-
-LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,