Extend flexible version check to packages

This commit is contained in:
Juergen Spitzmueller 2022-12-19 17:42:27 +01:00
parent 029adfa28c
commit 2e6ea5f613
5 changed files with 24 additions and 50 deletions

View File

@ -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@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}
@ -222,7 +207,7 @@
\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
@ -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.

View 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";

View 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;

View 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,";

View 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);
}