Guenter Milde wrote:
> > Do we have the possibility to check for package versions via configure?
> 
> If not, this should be added. It is useful in more than one case.

Is here a TeX method to find out a package version other than LaTeX's 
\@ifpackagelater? With the latter, the packages need to be loaded in advance, 
and we can't do that in checkconfig.ltx.

For the record, attached is my attempt (which doesn't work, since 
\@ifpackagelater does not work like this).

Jürgen
Index: lib/chkconfig.ltx
===================================================================
--- lib/chkconfig.ltx	(Revision 37384)
+++ lib/chkconfig.ltx	(Arbeitskopie)
@@ -19,6 +19,8 @@
 %%% 1- Add the command \TestPackage{<name>}. The syntax is:
 %%%    \TestPackage[<file>]{<name>}, which  tests whether <name>.sty
 %%%    (or <file>, if this optional parameter is provided) exists.
+%%%    If you require a specific version of a package, use.
+%%%    \TestPackageWithVersion[<file>]{<name>}{Date} instead.
 %%% 2- Add a description for <name> in doc/LaTeXConfig.lyx,
 %%%    containing in particular a line like
 %%%         Found: [InsetInfo]
@@ -51,7 +53,10 @@
 %      script generates the needed macro calls automatically.
 %    \TestPackage[<file>]{<name>} tests whether <name>.sty (or <file>,
 %      if it is provided) exists.
-%   Both commands call \AddVariable to give value 'yes' or 'no' to
+%    \TestPackageWithVersion[<file>]{<name>}{<date>} tests whether <name>.sty
+%      (or <file>, if it is provided) exists, and whether it is of or
+%      newer than the specified release date.
+%   All three commands call \AddVariable to give value 'yes' or 'no' to
 %   the variable chk_<name>.
 %%%
 
@@ -64,8 +69,8 @@
 \newcommand{\AddVariable}[2]{
   \immediate\write\vars{chk_#1='#2'}}
 
-\newcommand{\AddPackage}[1]{
-  \immediate\write\packages{#1}}
+\newcommand{\AddPackage}[2][]{
+  \immediate\write\packages{"#2"   "#1"}}
 
 % Tests whether an item is present
 % Syntax: \TestItem[<file>]{<name>}{<type>}{<ext>}{<iftrue>}{<iffalse>}
@@ -112,6 +117,10 @@
 \newcommand{\TestPackage}[2][\default]{
   \TestItem[#1]{#2}{package}{sty}{\AddPackage{#2}}{}}
 
+% \TestPackageWithVersion[file]{package}{version}
+\newcommand{\TestPackageWithVersion}[3][\default]{
+  \TestItem[#1]{#2}{package}{sty}{\@ifpackagelater{#2}{#3}{\AddPackage{#2}}{\AddPackage[outdated]{#2}}}{}}
+
 \newcommand{\TestDocClass}[2]{
    \def\layoutname{#1}  % remember the name of the layout file
    \@ifundefined{layout@#1}
@@ -269,6 +278,7 @@
 \TestPackage{fixltx2e}
 \TestPackage{fix-cm}
 \TestPackage{float}
+\TestPackageWithVersion{fontspec}{2010/07/11}
 \TestPackage{framed}
 \TestPackage{geometry}
 \TestPackage{graphicx}
Index: src/LaTeXFeatures.h
===================================================================
--- src/LaTeXFeatures.h	(Revision 37384)
+++ src/LaTeXFeatures.h	(Arbeitskopie)
@@ -90,6 +90,8 @@
 	static void getAvailable();
 	/// Is the (required) package available?
 	static bool isAvailable(std::string const & name);
+	/// Is the (required) package older than requested?
+	static bool isOutdated(std::string const & name);
 	/// Has the package been required?
 	bool isRequired(std::string const & name) const;
 	/* Is it necessary to load the package? This is true if
@@ -150,7 +152,7 @@
 	///
 	SnippetList preamble_snippets_;
 	/// The available (required) packages
-	typedef std::set<std::string> Packages;
+	typedef std::map<std::string, bool> Packages;
 	///
 	static Packages packages_;
 	///
Index: src/LaTeXFeatures.cpp
===================================================================
--- src/LaTeXFeatures.cpp	(Revision 37384)
+++ src/LaTeXFeatures.cpp	(Arbeitskopie)
@@ -347,7 +347,14 @@
 			finished = true;
 			break;
 		default:
-			packages_.insert(lex.getString());
+			string const pname = lex.getString();
+			LYXERR0("pname: " << pname);
+			if (!lex.next()) 
+				break;
+			// check if a package has been marked too old
+			bool outdated = (lex.getString() == "outdated");
+			LYXERR0("outdated: " << outdated);
+			packages_[pname] = outdated;
 		}
 	}
 }
@@ -440,6 +447,17 @@
 }
 
 
+bool LaTeXFeatures::isOutdated(string const & name)
+{
+	if (packages_.empty())
+		getAvailable();
+	string n = name;
+	if (suffixIs(n, ".sty"))
+		n.erase(name.length() - 4);
+	return (packages_.find(n) != packages_.end() && packages_.find(n)->second);
+}
+
+
 void LaTeXFeatures::addPreambleSnippet(string const & preamble)
 {
 	SnippetList::const_iterator begin = preamble_snippets_.begin();
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp	(Revision 37384)
+++ src/BufferParams.cpp	(Arbeitskopie)
@@ -2614,8 +2614,10 @@
 	 *       OldStyle, enable/disable the widget accordingly. 
 	*/
 	if (use_systemfonts) {
+		string const texmapping = LaTeXFeatures::isOutdated("fontspec") ?
+			"mapping=text-tex" : "Ligatures=TeX";
 		if (rm != "default") {
-			os << "\\setmainfont[Ligatures=TeX";
+			os << "\\setmainfont[" << texmapping;
 			if (osf)
 				os << ",Numbers=OldStyle";
 			os << "]{" << parseFontName(rm) << "}\n";
@@ -2625,10 +2627,10 @@
 			if (sfscale != 100)
 				os << "\\setsansfont[Scale=" 
 				   << float(sfscale) / 100 
-				   << ",Ligatures=TeX]{"
+				   << "," << texmapping << "]{"
 				   << sans << "}\n";
 			else
-				os << "\\setsansfont[Ligatures=TeX]{"
+				os << "\\setsansfont[" << texmapping << "]{"
 				   << sans << "}\n";
 		}
 		if (tt != "default") {

Reply via email to