]> git.lyx.org Git - features.git/commitdiff
Extend flexible version check to packages
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 19 Dec 2022 16:42:27 +0000 (17:42 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 19 Dec 2022 16:42:27 +0000 (17:42 +0100)
lib/chkconfig.ltx
src/BufferParams.cpp
src/LaTeXPackages.cpp
src/PDFOptions.cpp
src/insets/InsetTabular.cpp

index a9b82e6e4806698e5180fca318e6cca410f865af..d7c161c2ee1e69c6a218aeab57e1a511d051927f 100644 (file)
     #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@version{}
+   % The actual test only works after the package has been loaded
+   \IfFileExists{#1.sty}{%
+      \RequirePackage{#1}%
+      \protected@edef\package@@version{\csname ver@#1.sty\endcsname}%
+      \protected@edef\package@version{\expandafter\@parse@version\package@@version//00\@nil}%
+   }{}
+   \TestItem[#1]{#2}{package}{sty}{\AddPackage[\package@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}
 \AddVariable{fmtversion}{\fmtversion}
 
 %%% Store the current LaTeX version
-\AddPackage[\fmtversion]{LaTeX}
+\AddPackage[\expandafter\@parse@version\fmtversion//00\@nil]{LaTeX}
 
 %%% And now, the list of available languages
 % The trick is to know that \the\everyjob contains something like
 \TestPackage{array}
 \TestPackage{astron}
 \TestPackage{authordate1-4}
-\TestPackage{babel}
+\TestPackageAddVersion{babel}
 \TestPackage{beamerposter}
 \TestPackage{biblatex}
 \TestPackage{biblatex-chicago}
 \TestPackage[iso-8859-7.def]{greek-inputenc}
 \TestPackage{harvard}
 \TestPackage{hhline}
-\TestPackage{hyperref}
+\TestPackageAddVersion{hyperref}
 \TestPackage{hyphenat}
 \TestPackage{iftex}
 \TestPackage{ifthen}
 \TestPackage{mhchem}
 \TestPackage[mongolian.ldf]{mongolian}
 \TestPackage{mslapa}
-\TestPackage{multirow}
+\TestPackageAddVersion{multirow}
 \TestPackage{named}
 \TestPackage{natbib}
 \TestPackage{nicefrac}
 \TestPackage{thswitch}
 \TestPackage{tikz}
 \TestPackage[turkmen.ldf]{turkmen}
+\TestPackageAddVersion{ucs}
 \TestPackage{ulem}
 \TestPackage{undertilde}
 \TestPackage{unicode-math}
 %\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.
index 6e9cdd5f00f7054529e52add81bd0c2138c958ff..4d7550ac480532304ec8b45a9484e576d87ce382 100644 (file)
@@ -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";
index 4df2528c2e4d832e073350489ace80fdcd5db858..a8d775cfc16baa501da8f146c90dcc0a530aca49 100644 (file)
@@ -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;
index 1a15b0b217c395217621efbb5b002501d3e9cf8d..dc638f544dafb3638f6ad020fd7cff93c3414fd2 100644 (file)
@@ -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,";
 
index 082d4d97617e547e40b235a57756f9a5c17a3a82..e9c03b957598bb129b344422a8f7a01292c5645b 100644 (file)
@@ -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);
                }