[LyX/master] Extend flexible version check to packages

Juergen Spitzmueller spitz at lyx.org
Mon Dec 19 15:46:26 UTC 2022


commit 2e6ea5f61334889d5b1329b97c64e790f5f48199
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Mon Dec 19 17:42:27 2022 +0100

    Extend flexible version check to packages
---
 lib/chkconfig.ltx           |   58 ++++++++++++-------------------------------
 src/BufferParams.cpp        |    6 ++--
 src/LaTeXPackages.cpp       |    6 ++--
 src/PDFOptions.cpp          |    2 +-
 src/insets/InsetTabular.cpp |    2 +-
 5 files changed, 24 insertions(+), 50 deletions(-)

diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx
index a9b82e6..d7c161c 100644
--- a/lib/chkconfig.ltx
+++ b/lib/chkconfig.ltx
@@ -120,34 +120,19 @@
     #6
   \fi}
 
-% Tests whether an package is present in a specific version (or newer)
-% Syntax: \TestPackageVersion{<name>}{<yyyy/mm/dd>}
-
-\newcommand{\TestPackageVersion}[2]{
-   % The actual test only works if the package has been loaded before
-   \IfFileExists{#1.sty}{\RequirePackage{#1}}{}
-   \@TestPackageVersion{#1}{#2}
+% Tests whether an package is present and also adds the version to the package list
+\newcommand{\TestPackageAddVersion}[2][\default]{
+   \def\default{#2}
+   \def\package at version{}
+   % The actual test only works after the package has been loaded
+   \IfFileExists{#1.sty}{%
+      \RequirePackage{#1}%
+      \protected at edef\package@@version{\csname ver@#1.sty\endcsname}%
+      \protected at edef\package at version{\expandafter\@parse at version\package@@version//00\@nil}%
+   }{}
+   \TestItem[#1]{#2}{package}{sty}{\AddPackage[\package at version]{#2}}{}
 }
 
-\newcommand{\@TestPackageVersion}[2]{
-  \message{^^J\prefix checking for package #1 at least as of #2...}
-  \IfFileExists{#1.sty}
-  {
-    \@ifpackagelater{#1}{#2}{\existstrue}{\existsfalse}
-  }
-  {
-    \existsfalse
-  }
-  \ifexists
-    \message{yes^^J}
-    \AddVariable{#1}{yes}
-    \AddPackage{#1-#2}
-  \else
-    \message{no^^J}
-    \AddVariable{#1}{no}
-  \fi}
-
-
 % Adapted from ltxcheck.tex
 \newcommand{\TestFont}[2][\default]{
   \def\default{#2}
@@ -222,7 +207,7 @@
 \AddVariable{fmtversion}{\fmtversion}
 
 %%% Store the current LaTeX version
-\AddPackage[\fmtversion]{LaTeX}
+\AddPackage[\expandafter\@parse at version\fmtversion//00\@nil]{LaTeX}
 
 %%% And now, the list of available languages
 % The trick is to know that \the\everyjob contains something like
@@ -307,7 +292,7 @@
 \TestPackage{array}
 \TestPackage{astron}
 \TestPackage{authordate1-4}
-\TestPackage{babel}
+\TestPackageAddVersion{babel}
 \TestPackage{beamerposter}
 \TestPackage{biblatex}
 \TestPackage{biblatex-chicago}
@@ -356,7 +341,7 @@
 \TestPackage[iso-8859-7.def]{greek-inputenc}
 \TestPackage{harvard}
 \TestPackage{hhline}
-\TestPackage{hyperref}
+\TestPackageAddVersion{hyperref}
 \TestPackage{hyphenat}
 \TestPackage{iftex}
 \TestPackage{ifthen}
@@ -378,7 +363,7 @@
 \TestPackage{mhchem}
 \TestPackage[mongolian.ldf]{mongolian}
 \TestPackage{mslapa}
-\TestPackage{multirow}
+\TestPackageAddVersion{multirow}
 \TestPackage{named}
 \TestPackage{natbib}
 \TestPackage{nicefrac}
@@ -416,6 +401,7 @@
 \TestPackage{thswitch}
 \TestPackage{tikz}
 \TestPackage[turkmen.ldf]{turkmen}
+\TestPackageAddVersion{ucs}
 \TestPackage{ulem}
 \TestPackage{undertilde}
 \TestPackage{unicode-math}
@@ -562,18 +548,6 @@
 %\TestPackage{mathabx}
 %\TestPackage{mathdesign}% But see above!
 
-%%% Specific package versions
-% This introduces \babelfonts
-\TestPackageVersion{babel}{2017/11/03}
-% This introduces multiple paragraphs in multirows
-\TestPackageVersion{multirow}{2021/01/29}
-% With this version, hyperref option unicode is true
-% by default
-\TestPackageVersion{hyperref}{2021/02/04}
-% As of this version, the ucs package must be explicitly
-% loaded to get utf8x (rather than utf8) encoding tables
-\TestPackageVersion{ucs}{2022/08/07}
-
 %%% Document classes
 % The list of layout files has been put in this file here by the
 % configure script.
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 6e9cdd5..4d7550a 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -1922,7 +1922,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
 	if (useNonTeXFonts) {
 		// Babel (as of 2017/11/03) loads fontspec itself
 		if (!features.isProvided("fontspec")
-		    && !(features.useBabel() && features.isAvailable("babel-2017/11/03")))
+		    && !(features.useBabel() && features.isAvailableAtLeastFrom("babel", 2017, 11, 3)))
 			os << "\\usepackage{fontspec}\n";
 		if (features.mustProvide("unicode-math")
 		    && features.isAvailable("unicode-math"))
@@ -3448,7 +3448,7 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
 			// Thus we load ucs.sty in order to keep functionality
 			// that would otherwise be silently dropped.
 			if (doc_encoding == "utf8x"
-			    && features.isAvailable("ucs-2022/08/07")
+			    && features.isAvailableAtLeastFrom("ucs", 2022, 8, 7)
 			    && !features.isProvided("ucs"))
 				os << "\\usepackage{ucs}\n";
 			os << "\\usepackage[" << doc_encoding << "]{"
@@ -3507,7 +3507,7 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const
 		// As of 2017/11/03, Babel has its own higher-level
 		// interface on top of fontspec that is to be used.
 		bool const babelfonts = features.useBabel()
-				&& features.isAvailable("babel-2017/11/03");
+				&& features.isAvailableAtLeastFrom("babel", 2017, 11, 3);
 		string const texmapping =
 			(features.runparams().flavor == Flavor::XeTeX) ?
 			"Mapping=tex-text" : "Ligatures=TeX";
diff --git a/src/LaTeXPackages.cpp b/src/LaTeXPackages.cpp
index 4df2528..a8d775c 100644
--- a/src/LaTeXPackages.cpp
+++ b/src/LaTeXPackages.cpp
@@ -62,7 +62,7 @@ void LaTeXPackages::getAvailable()
 			string const p = lex.getString();
 			// Parse optional version info
 			lex.eatLine();
-			string const v = lex.getString();
+			string const v = trim(lex.getString());
 			packages_.insert(make_pair(p, v));
 		}
 		}
@@ -92,8 +92,8 @@ bool LaTeXPackages::isAvailableAtLeastFrom(string const & name,
 		getAvailable();
 
 	bool result = false;
-	// Check for yyyy-mm-dd
-	static regex const reg("([\\d]{4})-([\\d]{2})-([\\d]{2})");
+	// Check for yyyy[-/]mm[-/]dd
+	static regex const reg("([\\d]{4})[-/]?([\\d]{2})[-/]?([\\d]{2})");
 	for (auto const & package : packages_) {
 		if (package.first == name && !package.second.empty()) {
 			smatch sub;
diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp
index 1a15b0b..dc638f5 100644
--- a/src/PDFOptions.cpp
+++ b/src/PDFOptions.cpp
@@ -108,7 +108,7 @@ void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os,
 	// Since LyX uses unicode, also set the PDF strings to unicode strings
 	// with the hyperref option "unicode". This is only needed with pdflatex.
 	// As of 2021/02/04, unicode=true is default.
-	if (!LaTeXFeatures::isAvailable("hyperref-2021/02/04")
+	if (!LaTeXFeatures::isAvailableAtLeastFrom("hyperref", 2021, 2, 4)
 	     && !runparams.isFullUnicode() && !runparams.use_japanese)
 		opt += "unicode=true,";
 
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 082d4d9..e9c03b9 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -3272,7 +3272,7 @@ void Tabular::TeXRow(otexstream & os, row_type row,
 		} else if (!isPartOfMultiRow(row, c)) {
 			if (!runparams.nice)
 				os.texrow().start(par.id(), 0);
-			if (isMultiRow(cell) && !LaTeXFeatures::isAvailable("multirow-2021/01/29"))
+			if (isMultiRow(cell) && !LaTeXFeatures::isAvailableAtLeastFrom("multirow", 2021, 1, 29))
 				newrp.isNonLong = true;
 			inset->latex(os, newrp);
 		}


More information about the lyx-cvs mailing list