From 8bf5d4b4614bc45e727112cdb20e162da3e26717 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 24 Sep 2012 13:19:25 +0200 Subject: [PATCH] Very basic support for unicode-math With non-TeX fonts, you can select a 'Non-TeX Font Default' math font, which simply loads unicode-math without actually selecting a math font, this then uses the default math otf font, currently Latin Modern. Other fonts still need to be set manually in the preamble, via \setmathfont. The implementation suppresses unneeded package requests from unicodesymbols, but the output still uses macros instead of full unicode (both is possible with unicode-math). The whole thing is a proof of concept, and it needs to be tested. I have tested it with the math manual, which compiles and seems to display correctly if I remove some hardcoded package loadings. OTOH I have not much experience with math. This addresses #7449 partly. --- development/FORMAT | 6 ++++++ lib/chkconfig.ltx | 1 + lib/lyx2lyx/lyx_2_1.py | 4 +++- src/BufferParams.cpp | 7 ++++++- src/Encoding.cpp | 4 +++- src/frontends/qt4/GuiDocument.cpp | 11 +++++------ src/version.h | 4 ++-- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 83b73a1446..80d6ab374b 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,12 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- + +2012-09-24 Jürgen Spitzmüller + * Format incremented to 443: basic support for unicode-math: + Empty file format change (in case it turns out we need to + do something). + 2012-09-23 Jürgen Spitzmüller * Format incremented to 442: support for the newtxmath fonts: - \usepackage{newtxmath} > \font_math newtxmath diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index 1b82164a73..41ddde2c25 100644 --- a/lib/chkconfig.ltx +++ b/lib/chkconfig.ltx @@ -336,6 +336,7 @@ \TestPackage[turkmen.ldf]{turkmen} \TestPackage{ulem} \TestPackage{undertilde} +\TestPackage{unicode-math} \TestPackage{units} \TestPackage{url} \TestPackage{varioref} diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py index acb36d5a35..fb836ab306 100644 --- a/lib/lyx2lyx/lyx_2_1.py +++ b/lib/lyx2lyx/lyx_2_1.py @@ -1134,10 +1134,12 @@ convert = [ [439, []], [440, []], [441, [convert_mdnomath]], - [442, []] + [442, []], + [443, []] ] revert = [ + [442, []], [441, [revert_newtxmath]], [440, [revert_mdnomath]], [439, [revert_mathfonts]], diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index c53d0ec921..c99b467282 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -1419,8 +1419,13 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, if (useNonTeXFonts && !ams.empty()) os << from_ascii(ams); - if (useNonTeXFonts) + if (useNonTeXFonts) { os << "\\usepackage{fontspec}\n"; + if (fonts_math != "auto" && features.isAvailable("unicode-math")) { + features.require("unicode-math"); + os << "\\usepackage{unicode-math}\n"; + } + } // font selection must be done before loading fontenc.sty string const fonts = loadFonts(features); diff --git a/src/Encoding.cpp b/src/Encoding.cpp index b758787e28..6447e33eec 100644 --- a/src/Encoding.cpp +++ b/src/Encoding.cpp @@ -698,7 +698,9 @@ void Encodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed) (!for_mathed && !it->second.textcommand.empty()); bool const plain_utf8 = (features.runparams().encoding->name() == "utf8-plain"); // with utf8-plain, we only load packages when in mathed (see #7766) - if (math_mode || (use_math && !plain_utf8)) { + // and if we do not use unicode-math + if ((math_mode && !features.isRequired("unicode-math")) + || (use_math && !plain_utf8)) { if (!it->second.mathpreamble.empty()) { if (it->second.mathfeature()) { string feats = it->second.mathpreamble; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 6802f6f1ae..b461aa6910 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -1778,8 +1778,6 @@ 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 @@ -1902,6 +1900,11 @@ void GuiDocument::updateFontlist() fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default")); fontModule->fontsSansCO->addItem(qt_("Default"), QString("default")); fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default")); + QString unimath = qt_("Non-TeX Fonts Default"); + if (!LaTeXFeatures::isAvailable("unicode-math")) + unimath += qt_(" (not available)"); + fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto")); + fontModule->fontsMathCO->addItem(unimath, QString("default")); QFontDatabase fontdb; QStringList families(fontdb.families()); @@ -3203,14 +3206,10 @@ void GuiDocument::paramsToDialog() 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); diff --git a/src/version.h b/src/version.h index f3252ef2d2..99f411a1d9 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 442 // spitz: support for newtxmath -#define LYX_FORMAT_TEX2LYX 442 // spitz: support for newtxmath +#define LYX_FORMAT_LYX 443 // spitz: basic support for unicode-math +#define LYX_FORMAT_TEX2LYX 443 // spitz: basic support for unicode-math #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER