From 128c2b31d808c62f8e8b6eeb141922c233e31b93 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Thu, 7 May 2009 10:57:52 +0000 Subject: [PATCH] Avoid ugly macros in the preamble and protect underlined \cite commands in a clever way. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29558 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 3 +-- src/Font.cpp | 24 ++++++++++++------------ src/LaTeXFeatures.cpp | 32 -------------------------------- src/OutputParams.cpp | 2 +- src/OutputParams.h | 8 ++++++++ src/insets/InsetCitation.cpp | 8 +++++++- 6 files changed, 29 insertions(+), 48 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 988245498a..332d86feef 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -3,8 +3,7 @@ LyX file-format changes 2009-05-05 Pavel Sanda, Enrico Forestieri * Format incremented to 357: Change of the latex output for underline - from \underbar to ulem's \uline. This point also corresponds to - the introduction of \lyxuline etc. macros to avoid clash with \cite. + from \underbar to ulem's \uline. 2009-05-05 Pavel Sanda * Format incremented to 356: support for double and wave underline character diff --git a/src/Font.cpp b/src/Font.cpp index 0a9e302b60..4bf3040cd7 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -552,23 +552,27 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams, env = true; //We have opened a new environment } if (f.underbar() == FONT_ON) { - os << "\\lyxuline{"; + os << "\\uline{"; count += 10; + runparams.inulemcmd = true; env = true; //We have opened a new environment } if (f.strikeout() == FONT_ON) { - os << "\\lyxsout{"; + os << "\\sout{"; count += 9; + runparams.inulemcmd = true; env = true; //We have opened a new environment } if (f.uuline() == FONT_ON) { - os << "\\lyxuuline{"; + os << "\\uuline{"; count += 11; + runparams.inulemcmd = true; env = true; //We have opened a new environment } if (f.uwave() == FONT_ON) { - os << "\\lyxuwave{"; + os << "\\uwave{"; count += 10; + runparams.inulemcmd = true; env = true; //We have opened a new environment } // \noun{} is a LyX special macro @@ -638,21 +642,25 @@ int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams, if (f.underbar() == FONT_ON) { os << '}'; ++count; + runparams.inulemcmd = false; env = true; // Size change need not bother about closing env. } if (f.strikeout() == FONT_ON) { os << '}'; ++count; + runparams.inulemcmd = false; env = true; // Size change need not bother about closing env. } if (f.uuline() == FONT_ON) { os << '}'; ++count; + runparams.inulemcmd = false; env = true; // Size change need not bother about closing env. } if (f.uwave() == FONT_ON) { os << '}'; ++count; + runparams.inulemcmd = false; env = true; // Size change need not bother about closing env. } if (f.noun() == FONT_ON) { @@ -821,29 +829,21 @@ void Font::validate(LaTeXFeatures & features) const if (bits_.underbar() == FONT_ON) { 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 6842b3e0cf..efc3fc6a3b 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -164,23 +164,6 @@ 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" @@ -759,21 +742,6 @@ 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'; diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp index 564232b4ba..4e77c70ee3 100644 --- a/src/OutputParams.cpp +++ b/src/OutputParams.cpp @@ -19,7 +19,7 @@ namespace lyx { OutputParams::OutputParams(Encoding const * enc) - : flavor(LATEX), nice(false), moving_arg(false), + : flavor(LATEX), nice(false), moving_arg(false), inulemcmd(false), local_font(0), encoding(enc), free_spacing(false), use_babel(false), use_indices(false), use_japanese(false), linelen(0), depth(0), exportdata(new ExportData), diff --git a/src/OutputParams.h b/src/OutputParams.h index f0c06dc846..9ead2167f7 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -75,6 +75,14 @@ public: */ bool intitle; + /** inulemcmd == true means that the environment in which the + inset is typeset is part of a ulem command (\uline, \uuline, + \uwave, or \sout). Insets that output latex commands relying + on local assignments (such as \cite) should enclose such + commands in \mbox{} in order to avoid breakage. + */ + mutable bool inulemcmd; + /** the font at the point where the inset is */ Font const * local_font; diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 0c016bca5a..8e63c70397 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -535,13 +535,16 @@ void InsetCitation::tocString(odocstream & os) const // the \cite command is valid. Eg, the user has natbib enabled, inputs some // citations and then changes his mind, turning natbib support off. The output // should revert to \cite[]{} -int InsetCitation::latex(odocstream & os, OutputParams const &) const +int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const { CiteEngine cite_engine = buffer().params().citeEngine(); // FIXME UNICODE docstring const cite_str = from_utf8( asValidLatexCommand(getCmdName(), cite_engine)); + if (runparams.inulemcmd) + os << "\\mbox{"; + os << "\\" << cite_str; docstring const & before = getParam("before"); @@ -553,6 +556,9 @@ int InsetCitation::latex(odocstream & os, OutputParams const &) const os << '{' << cleanupWhitespace(getParam("key")) << '}'; + if (runparams.inulemcmd) + os << "}"; + return 0; }