=== modified file 'src/extension/internal/latex-text-renderer.cpp' --- src/extension/internal/latex-text-renderer.cpp 2015-10-29 22:24:26 +0000 +++ src/extension/internal/latex-text-renderer.cpp 2016-05-24 16:11:21 +0000 @@ -328,36 +328,83 @@ os << "\\makebox(0,0)" << alignment << "{"; os << "\\smash{"; // smash the text, to be able to put the makebox coordinates at the baseline - // Walk through all spans in the text object. + + bool is_bold = false, is_italic = false, is_oblique = false, is_sub = false, is_super = false;; + bool last_is_bold = false, last_is_italic = false, last_is_oblique = false, last_is_sub = false, last_is_super = false; + + // Walk through all spans in the text object. // Write span strings to LaTeX, associated with font weight and style. Inkscape::Text::Layout const &layout = *(te_get_layout (textobj)); for (Inkscape::Text::Layout::iterator li = layout.begin(), le = layout.end(); li != le; li.nextStartOfSpan()) { - SPStyle const &spanstyle = *(sp_te_style_at_position (textobj, li)); - bool is_bold = false, is_italic = false, is_oblique = false; - - if (spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_500 || + + SPStyle const &spanstyle = *(sp_te_style_at_position (textobj, li)); + is_bold = false, is_italic = false, is_oblique = false, is_sub = false, is_super = false; + + if ( (spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_500 || spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_600 || spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_700 || spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_800 || spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_900 || spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_BOLD || - spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_BOLDER) - { - is_bold = true; - os << "\\textbf{"; - } - if (spanstyle.font_style.computed == SP_CSS_FONT_STYLE_ITALIC) - { - is_italic = true; - os << "\\textit{"; - } - if (spanstyle.font_style.computed == SP_CSS_FONT_STYLE_OBLIQUE) + spanstyle.font_weight.computed == SP_CSS_FONT_WEIGHT_BOLDER) ) + { + is_bold =true; + } + if ( spanstyle.font_style.computed == SP_CSS_FONT_STYLE_ITALIC ) + { + is_italic = true; + } + if (spanstyle.font_style.computed == SP_CSS_FONT_STYLE_OBLIQUE ) { is_oblique = true; - os << "\\textsl{"; // this is an accurate choice if the LaTeX chosen font matches the font in Inkscape. Gives bad results when it is not so... } + /* + spanstyle.baseline_shift.computed returns different values which i could not fully understand + but they are <0 when subscripted and >0 when superscripted would be my choice. + */ + if (spanstyle.baseline_shift.computed < 0 ) + { + is_sub = true; + } + if (spanstyle.baseline_shift.computed > 0) + { + is_super = true; + } + + // close previous environment + if (!is_oblique && last_is_oblique) { os << "}"; last_is_oblique = false; }// oblique end + if (!is_italic && last_is_italic) { os << "}"; last_is_italic = false; } // italic end + if (!is_bold && last_is_bold) { os << "}"; last_is_bold = false; } // bold end + if (!is_sub && last_is_sub) { os << "}"; last_is_sub = false; } // subscript end + if (!is_super && last_is_super) { os << "}"; last_is_super = false; } // superscript end + + if ( is_bold && !last_is_bold) + { + os << "\\textbf{"; + last_is_bold = true; + } + if (is_italic && !last_is_italic) + { + os << "\\textit{"; + last_is_italic = true; + } + if (is_oblique && !last_is_oblique) + { + os << "\\textsl{"; // this is an accurate choice if the LaTeX chosen font matches the font in Inkscape. Gives bad results when it is not so... + last_is_oblique = true; + } + if (is_sub && !last_is_sub ) + { + os << "\\textsubscript{"; // Latex subscript and Open Bracket + last_is_sub = true; + } + if (is_super && !last_is_super) + { + os << "\\textsuperscript{"; // Latex superscript and Open Bracket + last_is_super = true; + } Inkscape::Text::Layout::iterator ln = li; ln.nextStartOfSpan(); @@ -372,19 +419,22 @@ os << spanstr_new; g_strfreev(splitstr); g_free(spanstr_new); - - if (is_oblique) { os << "}"; } // oblique end - if (is_italic) { os << "}"; } // italic end - if (is_bold) { os << "}"; } // bold end } + // close the last environment + if (is_oblique ) { os << "}"; } // oblique end + if (is_italic) { os << "}"; } // italic end + if (is_bold) { os << "}"; } // bold end + if (is_sub) { os << "}"; } // subscript end + if (is_super) { os << "}"; } // superscript end + + os << "}"; // smash end if (has_rotation) { os << "}"; // rotatebox end } os << "}"; //makebox end os << "}%\n"; // put end - fprintf(_stream, "%s", os.str().c_str()); }