背景
我为我的大学开设了一门论文课程。课程的变更频率比我希望的要高,这取决于大学论文办公室的想法,他们显然没有其他事情可做。最终结果是,我收到的最常见的支持请求来自使用课程过时版本的人(尽管文档警告他们应该确保拥有最新版本。)
问题
我如何强制或强烈鼓励用户使用最新版本的软件包?
需要
- 应该在类内工作(即文档不是解决方案)
- 理想情况下应该允许类发出警告或错误(取决于我想要的严厉程度)
- 不应该要求
--shell-escape
编译 - 不需要万无一失,但应该能够捕捉到过时的 TeXLive
- 应该可以与 TeXLive 和 MikTeX 一起使用
未回答
我非常清楚,在某些情况下可能需要使用旧版本的类,例如重新编译基于旧版本的论文,但这些情况通常无论如何都需要旧版本本身,并且可以单独处理。所以请不要评论为什么我问的是馊主意一般来说。 -
答案1
这花费了大量时间来拼凑,而且无法检查 MiKTeX 的旧版本(我手头没有副本)。但它确实会检查模板的过旧程度以及 TeX Live 的过时版本。
致谢:
- 扬尼斯的回答到datetime 和 datenumber 包冲突吗?
- 马丁的回答到有没有办法从包内部检测是否使用了 MiKTeX?
- egreg 的回答到在 pdflatex 中获取 Texlive 版本?
结果是,最低 TL 版本为 2015,模板日期已接近两年:
\documentclass{article}
\usepackage{ifthen}
\usepackage{datenumber}
% https://tex.stackexchange.com/a/8677
\newcounter{datetoday}\newcounter{dayssince}
\newcommand{\daydifftoday}[3]{%
\setmydatenumber{datetoday}{\the\year}{\the\month}{\the\day}%
\setmydatenumber{dayssince}{#1}{#2}{#3}%
\addtocounter{dayssince}{-\thedatetoday}%
}
% https://tex.stackexchange.com/a/10073
\newif\ifmiktex
\newif\iftexlive
\begingroup
\makeatletter
\def\MiKTeX{MiKTeX}
\@onelevel@sanitize\MiKTeX
\def\TeXLive{TeX Live}
\@onelevel@sanitize\TeXLive
\def\WebIIC{Web2C}
\@onelevel@sanitize\WebIIC
% Test if \pdftexbanner exists, which is the case for latex, pdflatex and lualatex
% but not xelatex.
\expandafter\ifx\csname pdftexbanner\endcsname\relax
\PackageWarning{ifdistro}
{Primitive \string\pdftexbanner\space not found!\MessageBreak
Switches \expandafter\string\csname ifmiktex\endcsname\space
and \expandafter\string\csname iftexlive\endcsname\space
will not be set\@gobble}% gobbles the "on line X" part
\else
% Scans for 'MiKTeX' string with catcode 12 (other)
\expandafter\def\expandafter\testmiktex\expandafter#\expandafter1\MiKTeX#2\relax{%
\ifx\empty#2\empty
\global\miktexfalse
\else
\global\miktextrue
\fi
}
\expandafter\expandafter
\expandafter\testmiktex\expandafter\pdftexbanner\MiKTeX\relax\relax
\ifmiktex\else
% Scans for 'TeX Live' string with catcode 12 (other)
\expandafter\def\expandafter\testtexlive\expandafter#\expandafter1\TeXLive#2\relax{%
\ifx\empty#2\empty
\global\texlivefalse
\else
\global\texlivetrue
\fi
}
\expandafter\expandafter
\expandafter\testtexlive\expandafter\pdftexbanner\TeXLive\relax\relax
\iftexlive\else
% Scans for 'Web2C' string with catcode 12 (other)
% This string is used by TeX Live under MS Windows
\expandafter\def\expandafter\testtexlive\expandafter#\expandafter1\WebIIC#2\relax{%
\ifx\empty#2\empty
\global\texlivefalse
\else
\global\texlivetrue
\fi
}
\expandafter\expandafter
\expandafter\testtexlive\expandafter\pdftexbanner\TeXLive\relax\relax
\fi\fi
\fi
\endgroup
% https://tex.stackexchange.com/a/205212
\def\gettexliveversion#1(#2 #3 #4#5#6#7#8)#9\relax{#4#5#6#7}
\edef\texliveversion{\expandafter\gettexliveversion\pdftexbanner\relax}
\AtBeginDocument{
\daydifftoday{2013}{10}{08}
\ifthenelse{\numexpr-\thedayssince>365}{%
{\noindent \Large Greetings, user. This template is over a year old, so you should check the website for updates. The graduate school has almost certainly created some new rules by now.}
}{}
\iftexlive
\ifnum\texliveversion<2015
{\noindent \Large We're on an old version of \TeX{} Live: \texliveversion, go update it.}
\fi
\fi
}
\begin{document}
\section{One}
\end{document}
祝你好运,无偿论文班维护者兄弟会的成员。
答案2
这段代码可以编译,从九月到四月
\ifnum \month>3
\ifnum\month<9
\errmessage{your class version is out of date}\fi\fi
\documentclass{article}
\begin{document}
bla
\end{document}
这段代码可以编译,从一月到八月
\ifnum\month>7 \errmessage{your class version is out of date}\fi
\documentclass{article}
\begin{document}
bla
\end{document}