]> git.lyx.org Git - features.git/commitdiff
Allow for general package options for LaTeX font packages (needed e.g. by mathdesign)
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 18 Aug 2012 11:10:34 +0000 (13:10 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 18 Aug 2012 11:10:34 +0000 (13:10 +0200)
lib/latexfonts
src/LaTeXFonts.cpp
src/LaTeXFonts.h

index 794039a091f0d86c6addcbfb99550106a9179171..681831d1867714f1f0d61781f987de8c98013868 100644 (file)
@@ -13,6 +13,7 @@
 #      AltPackages        <alternative packages (comma-separated)>
 #      OT1Package         <alternative package specifically for OT1 encoding>
 #      CompletePackage    <alternative package for the complete family>
+#      PackageOptions     <general options to be passed to the package>
 #      OsfOption          <option for oldstyle figure support>
 #      ScOption           <option for true smallcaps support>
 #      OsfScOption        <option for combined osf and true smallcaps support>
 #   done.
 # * "SwitchDefault 1" makes the font to be loaded by switching the default
 #   family to <name> (e.g., \renewcommand{\rmdefault}{cmr}), whereas
-#   Package <package> loads it via \usepackage{package}. Normally, only
-#   one of these options is used per font.
+#   Package <package> loads it via \usepackage{package}. Only one of these
+#   options is used per font (SwitchDefault takes precendende). Note that
+#   SwitchDefault uses the font name.
 # * If AltPackages are defined, LyX will try to load them in the defined
 #   order if the main package is not available. So
 #       Package          mathptmx
 #       AltPackages      mathptm,times
 #   will try to load mathptm if mathptmx is not available and then times
 #   if mathptm is not available either.
+#   No options will be passed to alternative packages!
 # * If Requires is set, LyX will check for this. If not, it will check
 #   for Package and AltPackages.
 # * OT1Package will load the defined package instead of the default
 #   package if the font encoding is OT1. This is necessary since some
 #   newer packages for a font do not support this encoding.
 #   The value "none" tells LyX not to load a package in OT1 encoding.
+#   No options will be passed to OT1 packages!
 # * CompletePackage is a package that 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" as opposed to "beraserif").
index 562a8fcd49584baff3172d4da03690d3aa5fcb32..6f89cd113107456984a8c2e67f138d91c80f9c04 100644 (file)
@@ -79,7 +79,7 @@ bool LaTeXFont::providesScale(bool ot1) const
 }
 
 
-string const LaTeXFont::getAvailablePackage(bool dryrun, bool ot1, bool complete)
+string const LaTeXFont::getAvailablePackage(bool dryrun, bool ot1, bool complete, bool & alt)
 {
        if (ot1 && !ot1package_.empty()) {
                if (ot1package_ != "none"
@@ -103,8 +103,10 @@ string const LaTeXFont::getAvailablePackage(bool dryrun, bool ot1, bool complete
                        return to_ascii(package_);
                else if (!altpackages_.empty()) {
                        for (size_t i = 0; i < altpackages_.size(); ++i) {
-                               if (LaTeXFeatures::isAvailable(to_ascii(altpackages_[i])))
+                               if (LaTeXFeatures::isAvailable(to_ascii(altpackages_[i]))) {
+                                       alt = true;
                                        return to_ascii(altpackages_[i]);
+                               }
                        }
                }
                // Output unavailable packages in source preview
@@ -126,7 +128,11 @@ string const LaTeXFont::getPackageOptions(bool ot1, bool sc, bool osf, int scale
                return string();
 
        ostringstream os;
+       if (!packageoption_.empty())
+               os << to_ascii(packageoption_);
        if (sc && osf && providesOSF() && providesSC()) {
+               if (!os.str().empty())
+                       os << ',';
                if (!osfscoption_.empty())
                        os << to_ascii(osfscoption_);
                else
@@ -164,9 +170,11 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
                                                  "is not available on your system. LyX will fall back to the default font."),
                                                requires_, guiname_), true);
        } else {
+               bool alt = false;
                string const package =
-                       getAvailablePackage(dryrun, ot1, complete);
-               string const packageopts = getPackageOptions(ot1, sc, osf, scale);
+                       getAvailablePackage(dryrun, ot1, complete, alt);
+               // Package options are not for alternative packages
+               string const packageopts = alt ? string() : getPackageOptions(ot1, sc, osf, scale);
                if (packageopts.empty() && !package.empty())
                        os << "\\usepackage{" << package << "}\n";
                else if (!packageopts.empty() && !package.empty())
@@ -192,6 +200,7 @@ bool LaTeXFont::readFont(Lexer & lex)
                LF_OSFSCOPTION,
                LF_OT1_PACKAGE,
                LF_PACKAGE,
+               LF_PACKAGEOPTION,
                LF_REQUIRES,
                LF_SCALEOPTION,
                LF_SCOPTION,
@@ -210,6 +219,7 @@ bool LaTeXFont::readFont(Lexer & lex)
                { "osfscoption",          LF_OSFSCOPTION },
                { "ot1package",           LF_OT1_PACKAGE },
                { "package",              LF_PACKAGE },
+               { "packageoption",        LF_PACKAGEOPTION },
                { "requires",             LF_REQUIRES },
                { "scaleoption",          LF_SCALEOPTION },
                { "scoption",             LF_SCOPTION },
@@ -269,6 +279,9 @@ bool LaTeXFont::readFont(Lexer & lex)
                case LF_PACKAGE:
                        lex >> package_;
                        break;
+               case LF_PACKAGEOPTION:
+                       lex >> packageoption_;
+                       break;
                case LF_REQUIRES:
                        lex >> requires_;
                        break;
index d12738efbe39c2ceeac4ac6e255f66b209b332b1..b4d7d4349667a79506ccbd0d0a7caec03d328b25 100644 (file)
@@ -43,6 +43,8 @@ public:
        docstring const & ot1package() { return ot1package_; }
        /// A package that provides Old Style Figures for this font
        docstring const & osfpackage() { return osfpackage_; }
+       /// A package option needed to load this font
+       docstring const & packageoption() { return packageoption_; }
        /// A package option for Old Style Figures
        docstring const & osfoption() { return osfoption_; }
        /// A package option for true SmallCaps
@@ -75,7 +77,8 @@ private:
        /// Return the preferred available package 
        std::string const getAvailablePackage(bool dryrun,
                                              bool ot1,
-                                             bool complete);
+                                             bool complete,
+                                             bool & alt);
        /// Return the package options
        std::string const getPackageOptions(bool ot1,
                                            bool sc,
@@ -98,6 +101,8 @@ private:
        ///
        docstring osfpackage_;
        ///
+       docstring packageoption_;
+       ///
        docstring osfoption_;
        ///
        docstring scoption_;