diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index c98e1f9d97..55c2fa1c98 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -1445,9 +1445,13 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, os << '{' << from_ascii(tclass.latexname()) << "}\n"; // end of \documentclass defs - // if we use fontspec, we have to load the AMS packages here + // if we use fontspec or newtxmath, we have to load the AMS packages here string const ams = features.loadAMSPackages(); - if (useNonTeXFonts && !ams.empty()) + bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1"); + bool const use_newtxmath = + theLaTeXFonts().getLaTeXFont(from_ascii(fonts_math)).getUsedPackage( + ot1, false, false) == "newtxmath"; + if ((useNonTeXFonts || use_newtxmath) && !ams.empty()) os << from_ascii(ams); if (useNonTeXFonts) { diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index d4074d6109..9292938c0f 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -851,10 +851,15 @@ string const LaTeXFeatures::getPackages() const // The rest of these packages are somewhat more complicated // than those above. - // if fontspec is used, AMS packages have to be loaded before - // fontspec (in BufferParams) + // if fontspec or newtxmath is used, AMS packages have to be loaded + // before fontspec (in BufferParams) string const amsPackages = loadAMSPackages(); - if (!params_.useNonTeXFonts && !amsPackages.empty()) + bool const ot1 = (params_.font_encoding() == "default" || params_.font_encoding() == "OT1"); + bool const use_newtxmath = + theLaTeXFonts().getLaTeXFont(from_ascii(params_.fonts_math)).getUsedPackage( + ot1, false, false) == "newtxmath"; + + if (!params_.useNonTeXFonts && !use_newtxmath && !amsPackages.empty()) packages << amsPackages; // fixltx2e must be loaded after amsthm, since amsthm produces an error with @@ -863,9 +868,9 @@ string const LaTeXFeatures::getPackages() const if (mustProvide("fixltx2e")) packages << "\\usepackage{fixltx2e}\n"; - if (mustProvide("cancel") && - params_.use_package("cancel") != BufferParams::package_off) - packages << "\\usepackage{cancel}\n"; + if (mustProvide("cancel") && + params_.use_package("cancel") != BufferParams::package_off) + packages << "\\usepackage{cancel}\n"; // wasysym is a simple feature, but it must be after amsmath if both // are used // wasysym redefines some integrals (e.g. iint) from amsmath. That diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp index e37ad2e945..676179f5a5 100644 --- a/src/LaTeXFonts.cpp +++ b/src/LaTeXFonts.cpp @@ -193,6 +193,15 @@ docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath) } +docstring const LaTeXFont::getUsedPackage(bool ot1, bool complete, bool nomath) +{ + docstring const usedfont = getUsedFont(ot1, complete, nomath); + if (usedfont.empty()) + return docstring(); + return theLaTeXFonts().getLaTeXFont(usedfont).package(); +} + + string const LaTeXFont::getAvailablePackage(bool dryrun) { if (package_.empty()) diff --git a/src/LaTeXFonts.h b/src/LaTeXFonts.h index 8c9da88e5e..a50a0770d9 100644 --- a/src/LaTeXFonts.h +++ b/src/LaTeXFonts.h @@ -82,6 +82,8 @@ public: int const & scale = 100); /// Return the actually used font docstring const getUsedFont(bool ot1, bool complete, bool nomath); + /// Return the actually used package + docstring const getUsedPackage(bool ot1, bool complete, bool nomath); /// bool read(Lexer & lex); ///