The branch, master, has been updated. - Log -----------------------------------------------------------------
commit 8f9898994d93d8f215f041bf42df0e06d028bbee Author: Juergen Spitzmueller <[email protected]> Date: Sat Sep 22 17:44:00 2012 +0200 Basic UI for math (TeX) fonts This addresses #6543 by adding an option to prevent fonts such as Palatino and Times to automatically adapt the math font (IOW it lets you load the text font only for a bunch of fonts where this is easily possible). Furthermore it adds an interface to select a specific math font, which is defined in latexfonts. Currently, this is only euler (the only one I know), but if there are other math-only tex fonts, they can be added easily (but note that this changes the file format). Non-TeX math fonts are not yet supported. Eventually, unicode-math support can use the existing UI, but this is not on my agenda. diff --git a/development/FORMAT b/development/FORMAT index f75d182..5b4e68c 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -12,6 +12,16 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2012-09-22 Jürgen Spitzmüller <[email protected]> + * Format incremented to 440 + Math (TeX) font UI. + New Buffer param "\math_font <value>", + supported values are: + * "auto": automatically adapt math font (the status quo ante). + * "default": use class default, i.e. prevent TeX font packages + from changing the math font, if possible. + * "eulervm": use the eulervm package. + 2012-09-19 Jürgen Spitzmüller <[email protected]> * Format incremented to 439 Support for the MinionPro LaTeX font. diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index cc0b876..e2be1a8 100644 --- a/lib/chkconfig.ltx +++ b/lib/chkconfig.ltx @@ -357,6 +357,7 @@ \TestPackage{ccfonts} \TestPackage{cmbright} \TestPackage{eco} +\TestPackage{eulervm} \TestPackage{feyn} \TestPackage{fourier} \TestPackage{libertine} diff --git a/lib/doc/LaTeXConfig.lyx b/lib/doc/LaTeXConfig.lyx index 55cb304..c05272d 100644 --- a/lib/doc/LaTeXConfig.lyx +++ b/lib/doc/LaTeXConfig.lyx @@ -1,5 +1,5 @@ #LyX 2.1 created this file. For more info see http://www.lyx.org/ -\lyxformat 438 +\lyxformat 440 \begin_document \begin_header \textclass article @@ -12,6 +12,7 @@ \font_roman default \font_sans default \font_typewriter default +\font_math auto \font_default_family default \use_non_tex_fonts false \font_sc false @@ -414,6 +415,34 @@ eco Computer Modern \family default font family. +\end_layout + +\begin_layout Subsection +Euler Virtual Math +\end_layout + +\begin_layout Description +Found: +\begin_inset Info +type "package" +arg "eulervm" +\end_inset + + +\end_layout + +\begin_layout Description +CTAN: +\family sans +fonts/eulervm/ +\end_layout + +\begin_layout Description +Notes: The +\family sans +eulervm +\family default + package provides access to the Euler math fonts. \end_layout diff --git a/lib/latexfonts b/lib/latexfonts index 273da4b..25ca2e1 100644 --- a/lib/latexfonts +++ b/lib/latexfonts @@ -6,13 +6,14 @@ # # Font <name> # GuiName "<Gui Name>" -# Family <rm|sf|tt> +# Family <rm|sf|tt|math> # SwitchDefault <0|1> # Package <LaTeX package to be loaded> # Requires <LaTeX package to test for> # AltFonts <alternative fonts (comma-separated)> # OT1Font <alternative font specifically for OT1 encoding> # CompleteFont <alternative package for the complete family> +# NoMathFont <alternative font that does not change math> # PackageOptions <general options to be passed to the package> # OsfOption <option for oldstyle figure support> # OsfFont <extra font for oldstyle figures> @@ -49,7 +50,7 @@ # for Package and AltFonts. # * OT1Font will load the defined font if the font encoding is OT1. This is # necessary since some newer font packages do not support this encoding. -# The value "none" tells LyX not to load a package in OT1 encoding. +# The value "none" tells LyX not to load any font in OT1 encoding. # OT1Fonts need to be defined separately using AltFont ... EndFont tags. # * The CompleteFont is loaded if the current font is selected as rm and # both sf and tt are set to "default" (this allows f. ex. to load "bera" @@ -148,6 +149,14 @@ Font lmodern GuiName "Latin Modern Roman" Family rm Package lmodern + NoMathFont lmr +EndFont + +AltFont lmr + GuiName "Latin Modern Roman" + Family rm + SwitchDefault 1 + Requires lmodern EndFont Font mdbch @@ -193,6 +202,16 @@ Font minionpro OsfDefault 1 Package MinionPro Provides amssymb,amsfonts + NoMathFont minionpro-nomath +EndFont + +AltFont minionpro-nomath + GuiName "Minion Pro" + Family rm + OsfOption lf + OsfDefault 1 + Package MinionPro + PackageOption onlytext EndFont Font newcent @@ -209,6 +228,7 @@ Font palatino OsfScOption osf Package mathpazo AltFonts mathpple,palatino-sty + NoMathFont ppl Requires psnfss EndFont @@ -216,6 +236,7 @@ AltFont mathpple GuiName "Palatino" Family rm Package mathpple + NoMathFont ppl EndFont AltFont palatino-sty @@ -224,11 +245,25 @@ AltFont palatino-sty Package palatino EndFont +AltFont ppl + GuiName "Palatino" + Family rm + OsfFont pplj + SwitchDefault 1 +EndFont + +AltFont pplj + GuiName "Palatino" + Family rm + SwitchDefault 1 +EndFont + Font times GuiName "Times Roman" Family rm Package mathptmx AltFonts mathptm,times-sty + NoMathFont ptm Requires psnfss EndFont @@ -236,6 +271,7 @@ AltFont mathptm GuiName "Times Roman" Family rm Package mathptm + NoMathFont ptm EndFont AltFont times-sty @@ -244,6 +280,12 @@ AltFont times-sty Package times EndFont +AltFont ptm + GuiName "Times Roman" + Family rm + SwitchDefault 1 +EndFont + Font tgbonum GuiName "TeX Gyre Bonum" Family rm @@ -410,3 +452,14 @@ Font txtt SwitchDefault 1 Requires txfonts EndFont + + +# +# MATH FONTS +# + +Font eulervm + GuiName "Euler VM" + Family math + Package eulervm +EndFont \ No newline at end of file diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py index a2fa26c..ed54c16 100644 --- a/lib/lyx2lyx/lyx_2_1.py +++ b/lib/lyx2lyx/lyx_2_1.py @@ -1004,6 +1004,39 @@ def revert_minionpro(document): add_to_preamble(document, [preamble]) document.header[i] = "\\font_roman default" + +def revert_mathfonts(document): + " Revert native math font definitions to LaTeX " + + i = find_token(document.header, "\\font_math", 0) + if i == -1: + return + if find_token(document.header, "\\use_non_tex_fonts false", 0) != -1: + val = get_value(document.header, "\\font_math", i) + if val == "eulervm": + add_to_preamble(document, "\\usepackage{eulervm}") + elif val == "default": + mathfont_dict = { + "lmodern": "\\renewcommand{\\rmdefault}{lmr}", + "minionpro": "\\usepackage[onlytext,lf]{MinionPro}", + "minionpro-osf": "\\usepackage[onlytext]{MinionPro}", + "palatino": "\\renewcommand{\\rmdefault}{ppl}", + "palatino-osf": "\\renewcommand{\\rmdefault}{pplj}", + "times": "\\renewcommand{\\rmdefault}{ptm}", + } + j = find_token(document.header, "\\font_roman", 0) + if j != -1: + rm = get_value(document.header, "\\font_roman", j) + k = find_token(document.header, "\\font_osf true", 0) + if k != -1: + rm += "-osf" + if rm in mathfont_dict.keys(): + add_to_preamble(document, mathfont_dict[rm]) + document.header[j] = "\\font_roman default" + if k != -1: + document.header[k] = "\\font_osf false" + del document.header[i] + ## # Conversion hub # @@ -1035,10 +1068,12 @@ convert = [ [436, []], [437, []], [438, []], - [439, []] + [439, []], + [440, []] ] revert = [ + [439, [revert_mathfonts]], [438, [revert_minionpro]], [437, [revert_ipadeco, revert_ipachar]], [436, [revert_texgyre]], diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index d205a35..2c96da3 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -376,6 +376,7 @@ BufferParams::BufferParams() fonts_roman = "default"; fonts_sans = "default"; fonts_typewriter = "default"; + fonts_math = "auto"; fonts_default_family = "default"; useNonTeXFonts = false; fonts_expert_sc = false; @@ -663,6 +664,9 @@ string BufferParams::readToken(Lexer & lex, string const & token, } else if (token == "\\font_typewriter") { lex.eatLine(); fonts_typewriter = lex.getString(); + } else if (token == "\\font_math") { + lex.eatLine(); + fonts_math = lex.getString(); } else if (token == "\\font_default_family") { lex >> fonts_default_family; } else if (token == "\\use_non_tex_fonts") { @@ -988,6 +992,7 @@ void BufferParams::writeFile(ostream & os) const << "\n\\font_roman " << fonts_roman << "\n\\font_sans " << fonts_sans << "\n\\font_typewriter " << fonts_typewriter + << "\n\\font_math " << fonts_math << "\n\\font_default_family " << fonts_default_family << "\n\\use_non_tex_fonts " << convert<string>(useNonTeXFonts) << "\n\\font_sc " << convert<string>(fonts_expert_sc) @@ -2776,10 +2781,9 @@ string const BufferParams::parseFontName(string const & name) const string const BufferParams::loadFonts(LaTeXFeatures & features) const { - // TODO: separate math fonts. - if (fonts_roman == "default" && fonts_sans == "default" - && fonts_typewriter == "default") + && fonts_typewriter == "default" + && (fonts_math == "default" || fonts_math == "auto")) //nothing to do return string(); @@ -2843,18 +2847,27 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1"); bool const dryrun = features.runparams().dryrun; bool const complete = (fonts_sans == "default" && fonts_typewriter == "default"); + bool const nomath = (fonts_math == "default"); // ROMAN FONTS os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_roman)).getLaTeXCode( - dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures); + dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures, + nomath); // SANS SERIF os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_sans)).getLaTeXCode( - dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures, fonts_sans_scale); + dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures, + nomath, fonts_sans_scale); // MONOSPACED/TYPEWRITER os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_typewriter)).getLaTeXCode( - dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures, fonts_typewriter_scale); + dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures, + nomath, fonts_typewriter_scale); + + // MATH + os << theLaTeXFonts().getLaTeXFont(from_ascii(fonts_math)).getLaTeXCode( + dryrun, ot1, complete, fonts_expert_sc, fonts_old_figures, + nomath); return os.str(); } diff --git a/src/BufferParams.h b/src/BufferParams.h index 0d45a45..306e5bc 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -248,6 +248,8 @@ public: std::string fonts_sans; /// the tt font std::string fonts_typewriter; + /// the math font + std::string fonts_math; /// the default family (rm, sf, tt) std::string fonts_default_family; /// use the fonts of the OS (OpenType, True Type) directly diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 7960ad2..a4955f1 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -442,13 +442,20 @@ bool LaTeXFeatures::isProvided(string const & name) const || params_.font_encoding() == "OT1"); bool const complete = (params_.fonts_sans == "default") && (params_.fonts_typewriter == "default"); + bool const nomath = (params_.fonts_math == "default"); return params_.documentClass().provides(name) || theLaTeXFonts().getLaTeXFont( - from_ascii(params_.fonts_roman)).provides(name, ot1, complete) + from_ascii(params_.fonts_roman)).provides(name, ot1, + complete, + nomath) || theLaTeXFonts().getLaTeXFont( - from_ascii(params_.fonts_sans)).provides(name, ot1, complete) + from_ascii(params_.fonts_sans)).provides(name, ot1, + complete, + nomath) || theLaTeXFonts().getLaTeXFont( - from_ascii(params_.fonts_typewriter)).provides(name, ot1, complete); + from_ascii(params_.fonts_typewriter)).provides(name, ot1, + complete, + nomath); } bool LaTeXFeatures::mustProvide(string const & name) const diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp index 08a40ba..2798bb0 100644 --- a/src/LaTeXFonts.cpp +++ b/src/LaTeXFonts.cpp @@ -40,11 +40,13 @@ LaTeXFont LaTeXFont::altFont(docstring const & name) } -bool LaTeXFont::available(bool ot1) +bool LaTeXFont::available(bool ot1, bool nomath) { - if (ot1 && !ot1font_.empty()) + if (nomath && !nomathfont_.empty()) + return altFont(nomathfont_).available(ot1, nomath); + else if (ot1 && !ot1font_.empty()) return (ot1font_ == "none") ? - true : altFont(ot1font_).available(ot1); + true : altFont(ot1font_).available(ot1, nomath); else if (requires_.empty() && package_.empty()) return true; else if (!requires_.empty() @@ -55,7 +57,7 @@ bool LaTeXFont::available(bool ot1) return true; else if (!altfonts_.empty()) { for (size_t i = 0; i < altfonts_.size(); ++i) { - if (altFont(altfonts_[i]).available(ot1)) + if (altFont(altfonts_[i]).available(ot1, nomath)) return true; } } @@ -63,16 +65,29 @@ bool LaTeXFont::available(bool ot1) } -bool LaTeXFont::providesOSF(bool ot1, bool complete) +bool LaTeXFont::providesNoMath(bool ot1, bool complete) { - docstring const usedfont = getUsedFont(ot1, complete); + docstring const usedfont = getUsedFont(ot1, complete, false); if (usedfont.empty()) return false; else if (usedfont != name_) - return altFont(usedfont).providesOSF(ot1, complete); + return altFont(usedfont).providesNoMath(ot1, complete); + + return (!nomathfont_.empty() && available(ot1, true)); +} + + +bool LaTeXFont::providesOSF(bool ot1, bool complete, bool nomath) +{ + docstring const usedfont = getUsedFont(ot1, complete, nomath); + + if (usedfont.empty()) + return false; + else if (usedfont != name_) + return altFont(usedfont).providesOSF(ot1, complete, nomath); else if (!osffont_.empty()) - return altFont(osffont_).available(ot1); + return altFont(osffont_).available(ot1, nomath); else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_))) return false; @@ -80,14 +95,14 @@ bool LaTeXFont::providesOSF(bool ot1, bool complete) } -bool LaTeXFont::providesSC(bool ot1, bool complete) +bool LaTeXFont::providesSC(bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete); + docstring const usedfont = getUsedFont(ot1, complete, nomath); if (usedfont.empty()) return false; else if (usedfont != name_) - return altFont(usedfont).providesSC(ot1, complete); + return altFont(usedfont).providesSC(ot1, complete, nomath); else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_))) return false; @@ -95,28 +110,28 @@ bool LaTeXFont::providesSC(bool ot1, bool complete) } -bool LaTeXFont::providesScale(bool ot1, bool complete) +bool LaTeXFont::providesScale(bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete); + docstring const usedfont = getUsedFont(ot1, complete, nomath); if (usedfont.empty()) return false; else if (usedfont != name_) - return altFont(usedfont).providesScale(ot1, complete); + return altFont(usedfont).providesScale(ot1, complete, nomath); else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_))) return false; return (!scaleoption_.empty()); } -bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete) +bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete, bool nomath) { - docstring const usedfont = getUsedFont(ot1, complete); + docstring const usedfont = getUsedFont(ot1, complete, nomath); if (usedfont.empty()) return false; else if (usedfont != name_) - return altFont(usedfont).provides(name, ot1, complete); + return altFont(usedfont).provides(name, ot1, complete, nomath); else if (provides_.empty()) return false; @@ -128,12 +143,14 @@ bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete) } -docstring const LaTeXFont::getUsedFont(bool ot1, bool complete) +docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath) { - if (ot1 && !ot1font_.empty()) + if (nomath && !nomathfont_.empty() && available(ot1, true)) + return nomathfont_; + else if (ot1 && !ot1font_.empty()) return (ot1font_ == "none") ? docstring() : ot1font_; else if (family_ == "rm" && complete && !completefont_.empty() - && altFont(completefont_).available(ot1)) + && altFont(completefont_).available(ot1, nomath)) return completefont_; else if (switchdefault_) { if (requires_.empty() @@ -150,8 +167,8 @@ docstring const LaTeXFont::getUsedFont(bool ot1, bool complete) else if (!altfonts_.empty()) { for (size_t i = 0; i < altfonts_.size(); ++i) { LaTeXFont altf = altFont(altfonts_[i]); - if (altf.available(ot1)) - return altf.getUsedFont(ot1, complete); + if (altf.available(ot1, nomath)) + return altf.getUsedFont(ot1, complete, nomath); } } @@ -183,12 +200,13 @@ string const LaTeXFont::getAvailablePackage(bool dryrun) } -string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool osf, int scale) +string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool osf, + int scale, bool nomath) { ostringstream os; bool const needosfopt = (osf != osfdefault_); - bool const has_osf = providesOSF(ot1, complete); - bool const has_sc = providesSC(ot1, complete); + bool const has_osf = providesOSF(ot1, complete, nomath); + bool const has_sc = providesSC(ot1, complete, nomath); if (!packageoption_.empty()) os << to_ascii(packageoption_); @@ -212,7 +230,7 @@ string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool } if (scale != 100 && !scaleoption_.empty() - && providesScale(ot1, complete)) { + && providesScale(ot1, complete, nomath)) { if (!os.str().empty()) os << ','; os << subst(to_ascii(scaleoption_), "$$val", @@ -223,22 +241,22 @@ string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool sc, - bool osf, int const & scale) + bool osf, bool nomath, int const & scale) { ostringstream os; - docstring const usedfont = getUsedFont(ot1, complete); + docstring const usedfont = getUsedFont(ot1, complete, nomath); if (usedfont.empty()) return string(); else if (usedfont != name_) - return altFont(usedfont).getLaTeXCode(dryrun, ot1, complete, sc, osf, scale); + return altFont(usedfont).getLaTeXCode(dryrun, ot1, complete, sc, osf, nomath, scale); if (switchdefault_) { if (family_.empty()) { LYXERR0("Error: Font `" << name_ << "' has no family defined!"); return string(); } - if (available(ot1) || dryrun) + if (available(ot1, nomath) || dryrun) os << "\\renewcommand{\\" << to_ascii(family_) << "default}{" << to_ascii(name_) << "}\n"; else @@ -249,14 +267,14 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool } else { string const package = getAvailablePackage(dryrun); - string const packageopts = getPackageOptions(ot1, complete, sc, osf, scale); + string const packageopts = getPackageOptions(ot1, complete, sc, osf, scale, nomath); if (packageopts.empty() && !package.empty()) os << "\\usepackage{" << package << "}\n"; else if (!packageopts.empty() && !package.empty()) os << "\\usepackage[" << packageopts << "]{" << package << "}\n"; } - if (osf && providesOSF(ot1, complete) && !osffont_.empty()) - os << altFont(osffont_).getLaTeXCode(dryrun, ot1, complete, sc, osf, scale); + if (osf && providesOSF(ot1, complete, nomath) && !osffont_.empty()) + os << altFont(osffont_).getLaTeXCode(dryrun, ot1, complete, sc, osf, nomath, scale); return os.str(); } @@ -270,6 +288,7 @@ bool LaTeXFont::readFont(Lexer & lex) LF_END, LF_FAMILY, LF_GUINAME, + LF_NOMATHFONT, LF_OSFDEFAULT, LF_OSFFONT, LF_OSFOPTION, @@ -291,6 +310,7 @@ bool LaTeXFont::readFont(Lexer & lex) { "endfont", LF_END }, { "family", LF_FAMILY }, { "guiname", LF_GUINAME }, + { "nomathfont", LF_NOMATHFONT }, { "osfdefault", LF_OSFDEFAULT }, { "osffont", LF_OSFFONT }, { "osfoption", LF_OSFOPTION }, @@ -343,6 +363,9 @@ bool LaTeXFont::readFont(Lexer & lex) case LF_GUINAME: lex >> guiname_; break; + case LF_NOMATHFONT: + lex >> nomathfont_; + break; case LF_OSFOPTION: lex >> osfoption_; break; @@ -462,7 +485,7 @@ LaTeXFonts::TexFontMap LaTeXFonts::getLaTeXFonts() LaTeXFont LaTeXFonts::getLaTeXFont(docstring const & name) { - if (name == "default") + if (name == "default" || name == "auto") return LaTeXFont(); if (texfontmap_.empty()) readLaTeXFonts(); @@ -476,7 +499,7 @@ LaTeXFont LaTeXFonts::getLaTeXFont(docstring const & name) LaTeXFont LaTeXFonts::getAltFont(docstring const & name) { - if (name == "default") + if (name == "default" || name == "auto") return LaTeXFont(); if (texaltfontmap_.empty()) readLaTeXFonts(); diff --git a/src/LaTeXFonts.h b/src/LaTeXFonts.h index 034658e..d79d456 100644 --- a/src/LaTeXFonts.h +++ b/src/LaTeXFonts.h @@ -56,25 +56,28 @@ public: /// Alternative requirement to test for docstring const & requires() { return requires_; } /// Does this font provide a given \p feature - bool provides(std::string const & name, bool ot1, bool complete); + bool provides(std::string const & name, bool ot1, + bool complete, bool nomath); /// Issue the familydefault switch bool switchdefault() const { return switchdefault_; } /// Does the font provide Old Style Figures as default? bool osfDefault() const { return osfdefault_; } /// Is this font available? - bool available(bool ot1); + bool available(bool ot1, bool nomath); + /// Does this font provide an alternative without math? + bool providesNoMath(bool ot1, bool complete); /// Does this font provide Old Style Figures? - bool providesOSF(bool ot1, bool complete); + bool providesOSF(bool ot1, bool complete, bool nomath); /// Does this font provide optional true SmallCaps? - bool providesSC(bool ot1, bool complete); + bool providesSC(bool ot1, bool complete, bool nomath); /// Does this font provide scaling? - bool providesScale(bool ot1, bool complete); + bool providesScale(bool ot1, bool complete, bool nomath); /// Return the LaTeX Code std::string const getLaTeXCode(bool dryrun, bool ot1, bool complete, - bool sc, bool osf, + bool sc, bool osf, bool nomath, int const & scale = 100); /// Return the actually used font - docstring const getUsedFont(bool ot1, bool complete); + docstring const getUsedFont(bool ot1, bool complete, bool nomath); /// bool read(Lexer & lex); /// @@ -87,7 +90,8 @@ private: bool complete, bool sc, bool osf, - int scale); + int scale, + bool nomath); /// Return an alternative font LaTeXFont altFont(docstring const & name); /// @@ -103,6 +107,8 @@ private: /// docstring completefont_; /// + docstring nomathfont_; + /// docstring ot1font_; /// docstring osffont_; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index f5e96ad..6802f6f 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -168,6 +168,7 @@ vector<pair<string, QString> > pagestyles; QMap<QString, QString> rmfonts_; QMap<QString, QString> sffonts_; QMap<QString, QString> ttfonts_; +QMap<QString, QString> mathfonts_; } // anonymous namespace @@ -817,6 +818,10 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(ttChanged(int))); + connect(fontModule->fontsMathCO, SIGNAL(activated(int)), + this, SLOT(change_adaptor())); + connect(fontModule->fontsMathCO, SIGNAL(activated(int)), + this, SLOT(mathFontChanged(int))); connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(fontModule->fontencCO, SIGNAL(activated(int)), @@ -1773,6 +1778,8 @@ void GuiDocument::osFontsChanged(bool nontexfonts) fontModule->fontencLA->setEnabled(tex_fonts); fontModule->fontencCO->setEnabled(tex_fonts); + fontModule->fontsMathCO->setEnabled(tex_fonts); + fontModule->fontsMathLA->setEnabled(tex_fonts); if (!tex_fonts) fontModule->fontencLE->setEnabled(false); else @@ -1780,6 +1787,12 @@ void GuiDocument::osFontsChanged(bool nontexfonts) } +void GuiDocument::mathFontChanged(int) +{ + updateFontOptions(); +} + + void GuiDocument::updateFontOptions() { bool const tex_fonts = !fontModule->osFontsCB->isChecked(); @@ -1801,6 +1814,7 @@ void GuiDocument::updateFontOptions() fontModule->fontsRomanCO->currentIndex()).toString(); fontModule->fontScCB->setEnabled(providesSC(font)); fontModule->fontOsfCB->setEnabled(providesOSF(font)); + updateMathFonts(font); } @@ -1841,6 +1855,13 @@ bool GuiDocument::completeFontset() const } +bool GuiDocument::noMathFont() const +{ + return (fontModule->fontsMathCO->itemData( + fontModule->fontsMathCO->currentIndex()).toString() == "default"); +} + + void GuiDocument::updateTexFonts() { LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts(); @@ -1855,7 +1876,7 @@ void GuiDocument::updateTexFonts() } docstring const family = lf.family(); docstring guiname = translateIfPossible(lf.guiname()); - if (!lf.available(ot1())) + if (!lf.available(ot1(), noMathFont())) guiname += _(" (not installed)"); if (family == "rm") rmfonts_.insert(toqstr(guiname), toqstr(it->first)); @@ -1863,6 +1884,8 @@ void GuiDocument::updateTexFonts() sffonts_.insert(toqstr(guiname), toqstr(it->first)); else if (family == "tt") ttfonts_.insert(toqstr(guiname), toqstr(it->first)); + else if (family == "math") + mathfonts_.insert(toqstr(guiname), toqstr(it->first)); } } @@ -1872,6 +1895,7 @@ void GuiDocument::updateFontlist() fontModule->fontsRomanCO->clear(); fontModule->fontsSansCO->clear(); fontModule->fontsTypewriterCO->clear(); + fontModule->fontsMathCO->clear(); // With XeTeX, we have access to all system fonts, but not the LaTeX fonts if (fontModule->osFontsCB->isChecked()) { @@ -1912,6 +1936,14 @@ void GuiDocument::updateFontlist() fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value()); ++tti; } + + fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto")); + fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default")); + QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin(); + while (mmi != mathfonts_.constEnd()) { + fontModule->fontsMathCO->addItem(mmi.key(), mmi.value()); + ++mmi; + } } @@ -1925,6 +1957,24 @@ void GuiDocument::fontencChanged(int item) } +void GuiDocument::updateMathFonts(QString const & rm) +{ + if (fontModule->osFontsCB->isChecked()) + return; + QString const math = + fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString(); + int const i = fontModule->fontsMathCO->findData("default"); + if (providesNoMath(rm) && i == -1) + fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default")); + else if (!providesNoMath(rm) && i != -1) { + int const c = fontModule->fontsMathCO->currentIndex(); + fontModule->fontsMathCO->removeItem(i); + if (c == i) + fontModule->fontsMathCO->setCurrentIndex(0); + } +} + + void GuiDocument::romanChanged(int item) { if (fontModule->osFontsCB->isChecked()) @@ -1933,6 +1983,7 @@ void GuiDocument::romanChanged(int item) fontModule->fontsRomanCO->itemData(item).toString(); fontModule->fontScCB->setEnabled(providesSC(font)); fontModule->fontOsfCB->setEnabled(providesOSF(font)); + updateMathFonts(font); } @@ -2708,6 +2759,10 @@ void GuiDocument::applyView() fromqstr(fontModule->fontsTypewriterCO-> itemData(fontModule->fontsTypewriterCO->currentIndex()).toString()); + bp_.fonts_math = + fromqstr(fontModule->fontsMathCO-> + itemData(fontModule->fontsMathCO->currentIndex()).toString()); + QString const fontenc = fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString(); if (fontenc == "custom") @@ -3136,14 +3191,26 @@ void GuiDocument::paramsToDialog() } fontModule->fontsTypewriterCO->setCurrentIndex(tpos); + font = toqstr(bp_.fonts_math); + int mpos = fontModule->fontsMathCO->findData(font); + if (mpos == -1) { + mpos = fontModule->fontsMathCO->count(); + fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font); + } + fontModule->fontsMathCO->setCurrentIndex(mpos); + if (bp_.useNonTeXFonts && os_fonts_available) { fontModule->fontencLA->setEnabled(false); fontModule->fontencCO->setEnabled(false); fontModule->fontencLE->setEnabled(false); + fontModule->fontsMathCO->setEnabled(false); + fontModule->fontsMathLA->setEnabled(false); } else { fontModule->fontencLA->setEnabled(true); fontModule->fontencCO->setEnabled(true); fontModule->fontencLE->setEnabled(true); + fontModule->fontsMathCO->setEnabled(true); + fontModule->fontsMathLA->setEnabled(true); romanChanged(rpos); sansChanged(spos); ttChanged(tpos); @@ -3632,7 +3699,9 @@ bool GuiDocument::providesOSF(QString const & font) const // have OSF support. But how? return true; return theLaTeXFonts().getLaTeXFont( - qstring_to_ucs4(font)).providesOSF(ot1(), completeFontset()); + qstring_to_ucs4(font)).providesOSF(ot1(), + completeFontset(), + noMathFont()); } @@ -3641,7 +3710,9 @@ bool GuiDocument::providesSC(QString const & font) const if (fontModule->osFontsCB->isChecked()) return false; return theLaTeXFonts().getLaTeXFont( - qstring_to_ucs4(font)).providesSC(ot1(), completeFontset()); + qstring_to_ucs4(font)).providesSC(ot1(), + completeFontset(), + noMathFont()); } @@ -3650,7 +3721,19 @@ bool GuiDocument::providesScale(QString const & font) const if (fontModule->osFontsCB->isChecked()) return true; return theLaTeXFonts().getLaTeXFont( - qstring_to_ucs4(font)).providesScale(ot1(), completeFontset()); + qstring_to_ucs4(font)).providesScale(ot1(), + completeFontset(), + noMathFont()); +} + + +bool GuiDocument::providesNoMath(QString const & font) const +{ + if (fontModule->osFontsCB->isChecked()) + return false; + return theLaTeXFonts().getLaTeXFont( + qstring_to_ucs4(font)).providesNoMath(ot1(), + completeFontset()); } diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index dad82ea..9b03450 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -122,6 +122,7 @@ private Q_SLOTS: void deleteBoxBackgroundColor(); void languageChanged(int); void osFontsChanged(bool); + void mathFontChanged(int); void branchesRename(docstring const &, docstring const &); private: /// validate listings parameters and return an error message, if any @@ -234,6 +235,8 @@ private: bool providesSC(QString const & font) const; /// does this font provide size adjustment? bool providesScale(QString const & font) const; + /// does this font provide an alternative without math? + bool providesNoMath(QString const & font) const; /// void executeBranchRenaming() const; /// @@ -246,12 +249,16 @@ private: /// void updateTexFonts(); /// + void updateMathFonts(QString const & rm); + /// void updateFontOptions(); /// bool ot1() const; /// bool completeFontset() const; /// + bool noMathFont() const; + /// BufferParams bp_; /// List of names of available modules std::list<modInfoStruct> moduleNames_; diff --git a/src/frontends/qt4/ui/FontUi.ui b/src/frontends/qt4/ui/FontUi.ui index a266077..866e138 100644 --- a/src/frontends/qt4/ui/FontUi.ui +++ b/src/frontends/qt4/ui/FontUi.ui @@ -1,3 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>FontUi</class> <widget class="QWidget" name="FontUi"> @@ -23,7 +24,7 @@ </property> </widget> </item> - <item row="0" column="2" colspan="2"> + <item row="0" column="2"> <spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -53,7 +54,7 @@ </property> </widget> </item> - <item row="1" column="3"> + <item row="1" column="2"> <widget class="QLabel" name="BaseSizeLA"> <property name="text"> <string>&Base Size:</string> @@ -63,7 +64,7 @@ </property> </widget> </item> - <item row="1" column="4"> + <item row="1" column="3"> <widget class="QComboBox" name="fontsizeCO"> <property name="toolTip"> <string/> @@ -83,7 +84,7 @@ <item row="2" column="1"> <widget class="QComboBox" name="fontencCO"/> </item> - <item row="2" column="3" colspan="2"> + <item row="2" column="2" colspan="2"> <widget class="QLineEdit" name="fontencLE"> <property name="toolTip"> <string>Specify the font encoding (e.g., T1).</string> @@ -124,7 +125,7 @@ </property> </widget> </item> - <item row="4" column="3"> + <item row="4" column="2"> <widget class="QLabel" name="scaleSansLA"> <property name="text"> <string>S&cale (%):</string> @@ -134,7 +135,7 @@ </property> </widget> </item> - <item row="4" column="4"> + <item row="4" column="3"> <widget class="QSpinBox" name="scaleSansSB"> <property name="toolTip"> <string>Scale the Sans Serif font to match the base font's dimensions</string> @@ -164,7 +165,7 @@ </property> </widget> </item> - <item row="5" column="3"> + <item row="5" column="2"> <widget class="QLabel" name="scaleTypewriterLA"> <property name="text"> <string>Sc&ale (%):</string> @@ -174,7 +175,7 @@ </property> </widget> </item> - <item row="5" column="4"> + <item row="5" column="3"> <widget class="QSpinBox" name="scaleTypewriterSB"> <property name="toolTip"> <string>Scale the Typewriter font to match the base font's dimensions</string> @@ -188,6 +189,23 @@ </widget> </item> <item row="6" column="0"> + <widget class="QLabel" name="fontsMathLA"> + <property name="text"> + <string>&Math:</string> + </property> + <property name="buddy"> + <cstring>fontsMathCO</cstring> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QComboBox" name="fontsMathCO"> + <property name="toolTip"> + <string>Select the math typeface</string> + </property> + </widget> + </item> + <item row="7" column="0"> <widget class="QLabel" name="cjkFontLA"> <property name="text"> <string>C&JK:</string> @@ -197,14 +215,14 @@ </property> </widget> </item> - <item row="6" column="1"> + <item row="7" column="1"> <widget class="QLineEdit" name="cjkFontLE"> <property name="toolTip"> <string>Input the font to be used for Chinese, Japanese or Korean (CJK) script</string> </property> </widget> </item> - <item row="7" column="1" colspan="2"> + <item row="8" column="1"> <widget class="QCheckBox" name="fontScCB"> <property name="toolTip"> <string>Use a real small caps shape, if the font provides one</string> @@ -214,7 +232,7 @@ </property> </widget> </item> - <item row="8" column="1" colspan="2"> + <item row="9" column="1"> <widget class="QCheckBox" name="fontOsfCB"> <property name="toolTip"> <string>Use old style instead of lining figures</string> @@ -224,7 +242,7 @@ </property> </widget> </item> - <item row="9" column="1" colspan="2"> + <item row="10" column="1"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> diff --git a/src/version.h b/src/version.h index 10a2212..42dcffe 100644 --- a/src/version.h +++ b/src/version.h @@ -30,8 +30,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 439 // spitz: support MinionPro LaTeX font -#define LYX_FORMAT_TEX2LYX 439 // spitz: support MinionPro LaTeX font +#define LYX_FORMAT_LYX 440 // spitz: basic UI for math (TeX) fonts +#define LYX_FORMAT_TEX2LYX 440 // spitz: basic UI for math (TeX) fonts #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER ----------------------------------------------------------------------- Summary of changes: development/FORMAT | 10 ++++ lib/chkconfig.ltx | 1 + lib/doc/LaTeXConfig.lyx | 31 ++++++++++++- lib/latexfonts | 57 ++++++++++++++++++++++- lib/lyx2lyx/lyx_2_1.py | 37 ++++++++++++++- src/BufferParams.cpp | 25 ++++++++-- src/BufferParams.h | 2 + src/LaTeXFeatures.cpp | 13 ++++- src/LaTeXFonts.cpp | 93 +++++++++++++++++++++++-------------- src/LaTeXFonts.h | 22 ++++++--- src/frontends/qt4/GuiDocument.cpp | 91 ++++++++++++++++++++++++++++++++++-- src/frontends/qt4/GuiDocument.h | 7 +++ src/frontends/qt4/ui/FontUi.ui | 42 ++++++++++++----- src/version.h | 4 +- 14 files changed, 361 insertions(+), 74 deletions(-) hooks/post-receive -- The LyX Source Repository
