From cd62043a1b391ca396e5a690368a7e8864303cd3 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Wed, 6 May 2009 10:20:40 +0000 Subject: [PATCH] Solve problem with underlining citations. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29550 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/lyx_2_0.py | 18 ++++++++++++++++-- src/Font.cpp | 24 ++++++++++++++++-------- src/LaTeXFeatures.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index eb150330ba..153bcac7a8 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -435,6 +435,9 @@ def revert_backgroundcolor(document): return colorcode = get_value(document.header, '\\backgroundcolor', 0) del document.header[i] + # don't clutter the preamble if backgroundcolor is not set + if colorcode == "#ffffff": + continue # the color code is in the form #rrggbb where every character denotes a hex number # convert the string to an int red = string.atoi(colorcode[1:3],16) @@ -615,7 +618,7 @@ def revert_strikeout(document): def revert_uulinewave(document): - " Reverts \\uuline and \\uwave character style " + " Reverts \\uline, \\uuline, and \\uwave character styles " while True: i = find_token(document.body, '\\uuline', 0) if i == -1: @@ -624,8 +627,19 @@ def revert_uulinewave(document): while True: i = find_token(document.body, '\\uwave', 0) if i == -1: - return + break del document.body[i] + i = find_token(document.body, '\\bar under', 0) + if i == -1: + return + insert_to_preamble(0, document, + '% Commands inserted by lyx2lyx for proper underlining\n' + + '\\PassOptionsToPackage{normalem}{ulem}\n' + + '\\usepackage{ulem}\n' + + '\\let\\cite@rig\\cite\n' + + '\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}\n' + + ' \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}\n' + + '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n') ## diff --git a/src/Font.cpp b/src/Font.cpp index 0290f91961..0a9e302b60 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -552,23 +552,23 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams, env = true; //We have opened a new environment } if (f.underbar() == FONT_ON) { - os << "\\uline{"; + os << "\\lyxuline{"; count += 10; env = true; //We have opened a new environment } if (f.strikeout() == FONT_ON) { - os << "\\sout{"; - count += 6; + os << "\\lyxsout{"; + count += 9; env = true; //We have opened a new environment } if (f.uuline() == FONT_ON) { - os << "\\uuline{"; - count += 8; + os << "\\lyxuuline{"; + count += 11; env = true; //We have opened a new environment } if (f.uwave() == FONT_ON) { - os << "\\uwave{"; - count += 7; + os << "\\lyxuwave{"; + count += 10; env = true; //We have opened a new environment } // \noun{} is a LyX special macro @@ -819,23 +819,31 @@ void Font::validate(LaTeXFeatures & features) const LYXERR(Debug::LATEX, "Noun enabled. Font: " << to_utf8(stateText(0))); } if (bits_.underbar() == FONT_ON) { - LYXERR(Debug::LATEX, "font.underline: " << bits_.strikeout()); + LYXERR(Debug::LATEX, "font.underline: " << bits_.underbar()); features.require("ulem"); + features.require("boxcite"); + features.require("lyxuline"); LYXERR(Debug::LATEX, "Underline enabled. Font: " << to_utf8(stateText(0))); } if (bits_.strikeout() == FONT_ON) { LYXERR(Debug::LATEX, "font.strikeout: " << bits_.strikeout()); features.require("ulem"); + features.require("boxcite"); + features.require("lyxsout"); LYXERR(Debug::LATEX, "Strikeout enabled. Font: " << to_utf8(stateText(0))); } if (bits_.uuline() == FONT_ON) { LYXERR(Debug::LATEX, "font.uuline: " << bits_.uuline()); features.require("ulem"); + features.require("boxcite"); + features.require("lyxuuline"); LYXERR(Debug::LATEX, "Double underline enabled. Font: " << to_utf8(stateText(0))); } if (bits_.uwave() == FONT_ON) { LYXERR(Debug::LATEX, "font.uwave: " << bits_.uwave()); features.require("ulem"); + features.require("boxcite"); + features.require("lyxuwave"); LYXERR(Debug::LATEX, "Wavy underline enabled. Font: " << to_utf8(stateText(0))); } switch (bits_.color()) { diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index efc3fc6a3b..6842b3e0cf 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -164,6 +164,23 @@ static string const lyxdot_def = "%% A simple dot to overcome graphicx limitations\n" "\\newcommand{\\lyxdot}{.}\n"; +static string const boxcite_def = + "\\let\\cite@rig\\cite\n" + "\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}\n" + " \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}\n"; + +static string const lyxuline_def = + "\\newcommand{\\lyxuline}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n"; + +static string const lyxuuline_def = + "\\newcommand{\\lyxuuline}[1]{{\\let\\cite\\b@xcite\\uuline{#1}}}\n"; + +static string const lyxuwave_def = + "\\newcommand{\\lyxuwave}[1]{{\\let\\cite\\b@xcite\\uwave{#1}}}\n"; + +static string const lyxsout_def = + "\\newcommand{\\lyxsout}[1]{{\\let\\cite\\b@xcite\\sout{#1}}}\n"; + static string const changetracking_dvipost_def = "%% Change tracking with dvipost\n" "\\dvipostlayout\n" @@ -742,6 +759,21 @@ string const LaTeXFeatures::getMacros() const if (mustProvide("lyxline")) macros << lyxline_def << '\n'; + if (mustProvide("boxcite")) + macros << boxcite_def << '\n'; + + if (mustProvide("lyxuline")) + macros << lyxuline_def << '\n'; + + if (mustProvide("lyxuuline")) + macros << lyxuuline_def << '\n'; + + if (mustProvide("lyxuwave")) + macros << lyxuwave_def << '\n'; + + if (mustProvide("lyxsout")) + macros << lyxsout_def << '\n'; + if (mustProvide("noun")) macros << noun_def << '\n'; -- 2.39.5