8

Background

I maintain a thesis class for my university. The class changes more frequently that I would like based on the whims of the university thesis office who clearly have little else to occupy their time. The net result of this is that the most common support request I receive comes from people using an out of date version of the class (despite the documentation warning them that they should make sure they have the latest version.)

The Question

How can I force or strongly encourage users to use the most recent version of the package?

Desiderata

  • should work within the class itself (i.e., documentation is not a solution)
  • ideally should allow the class to issue a warning or error (depending on how draconian I want to be)
  • should not require --shell-escape for compilation
  • doesn't need to be foolproof, but should catch e.g., out of date TeXLive
  • should work with both TeXLive and MikTeX

Non-answers

I am more than aware that there are cases in which one might need to use an older version of the class, for example to recompile a thesis based on an older version, but these cases will typically require the old version itself anyway, and can be handled separately. So please, no comments on why what I'm asking is a bad idea in general. -

Alan Munn
  • 218,180
  • 3
    You can print "If we find out that you submitted your thesis with an old version, you will fail your studies". An optional "Bwahaha" might help. – percusse Sep 29 '15 at 18:14
  • 1
    @percusse No, that's what the thesis office does. And then I have to deal with the crap in the form of support requests... – Alan Munn Sep 29 '15 at 18:15
  • 3
    Haha, ever heard of call forwarding? On a serious note, put a date as a deadline and if the difference is more than six months or one year refuse to compile put a memo about this in the manual. Then they'll remember to update or RTFM. – percusse Sep 29 '15 at 18:17
  • 2
    Related: Difference between two dates. Set one date to your release date, and another to today. You may also be able to parse \pdftexbanner for a distribution version, as in Detecting which version of the LaTeX format is in use. – Mike Renfro Sep 29 '15 at 18:17
  • I second @percusse's suggestion. – Gonzalo Medina Sep 29 '15 at 18:22
  • +1 @percusse .

    – touhami Sep 29 '15 at 19:11
  • there's a "time bomb" in the diagrams package by paul taylor (see http://www.paultaylor.eu/diagrams/ since i'm not sure the most recent version is on ctan). although i have problems with that mechanism in that context, i think it could be very effective in a time-constrained thesis environment. (this is comparable to percusse's suggestion.) – barbara beeton Sep 29 '15 at 19:53
  • 1
    With the “time bomb” system you are forced to issue regular updates. On the other hand, I see no other means: an old version cannot be aware of a newer one. Programs that warn users about new versions make a query to some web site, something which would require -shell-escape unless you are able to convince Karl Berry into adding some script/program that can make such query to the ones allowed by the restricted shell escape. – egreg Sep 29 '15 at 20:25
  • Note that if you do this and you fail for any reason to issue an update, no students will be able to compile their theses at all. So be very, very sure that you will not get sick, forget, be run over by a bus, have to take leave, go on sabbatical etc. etc. Remember that if my thesis compiles at deadline - 10 mins and I make no changes, it is not unreasonable for me to expect it to compile at deadline - 5 mins as well. (Just to be sure, to resolve the last reference etc.) Personally, I think this is a really nasty idea. At least issue an error which allows the user to add an option to override. – cfr Oct 08 '15 at 02:16

2 Answers2

2

this code can compile, from september to April

\ifnum \month>3
        \ifnum\month<9
           \errmessage{your class version is out of date}\fi\fi
    \documentclass{article} 
    \begin{document}
    bla 
    \end{document}

this code can compile, from january to august

\ifnum\month>7 \errmessage{your class version is out of date}\fi
\documentclass{article} 
\begin{document}
bla 
\end{document}
touhami
  • 19,520
1

This took an annoying amount of time to piece together, and doesn't handle checking for old versions of MiKTeX (which I don't have a handy copy of). But it does check for excessive age of the template, and outdated versions of TeX Live.

Credits to:

Result, with minimum TL version of 2015, and a nearly two-year old template date:

enter image description here

\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}

Good luck, fellow member of the brotherhood of uncompensated thesis class maintainers.

Mike Renfro
  • 20,550
  • And if the maintainer is sick or has gone on sabbatical or forgotten, I can't compile even if the rules are the same? Moreover, this will force users to update right before their deadlines, if they are unlucky, with no prior warning. This is very likely to break things in many cases. At an absolute minimum, it should be possible to override this and the class should issue ample warnings before it does this. – cfr Oct 08 '15 at 02:21
  • This will also break compilation for all students using online servers for compilation and anybody who cannot easily update their distribution of TeX. (Great for cases where the institution itself provides TeX for students.) [I realise it compiles, technically. But you cannot submit with a banner like this.] Preparing my thesis in a word processor suddenly looks surprising attractive. – cfr Oct 08 '15 at 02:23
  • 1
    If it throws a warning instead of watermarking or otherwise changing a page, that fixes one concern. One could throw warnings at a one year age, errors at a two year age, etc. How it's handled is largely up to the maintainer. I can't speak for Alan, but I get students with old templates most every semester, because they get a copy from someone else instead of my site (linked from the grad school). And they only find out after they get flagged at the grad school and go into a panic at the deadline. – Mike Renfro Oct 08 '15 at 02:26
  • 1
    The important thing is detecting old distributions and/or templates. How the template reacts is entirely up to the maintainer. – Mike Renfro Oct 08 '15 at 02:28
  • @cfr I think you are reading way too much doom into this, especially since my question was explicitly about what kinds of things one could do. As Mike says, the majority of our 'bug' reports stem purely from people using an outdated version of the template or class and I was explicitly looking for proof-of-concept type answers on how best to solve this particular problem, which this answer clearly does. Thanks Mike! Of course there are various levels of draconianism one can resort to. And as a last resort your desperate student could always remove the code from the class themselves. – Alan Munn Oct 08 '15 at 02:42
  • @AlanMunn The question is reasonable. It is the answers which worry me. – cfr Oct 08 '15 at 03:02
  • 1
    Related: 5 year time bomb in LaTeX distributions, with rationales for and against. – Mike Renfro Oct 08 '15 at 12:14