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. -

  • 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
  • 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
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.

  • 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 8 '15 at 2: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 8 '15 at 2: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 8 '15 at 2: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 8 '15 at 2:28
  • 1
    Related: 5 year time bomb in LaTeX distributions, with rationales for and against. – Mike Renfro Oct 8 '15 at 12:14
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}
  • Thanks. This is a little too generic for my purposes in that I would need something more connected to actual dates. – Alan Munn Sep 30 '15 at 17:04
  • @AlanMunn I don't understand? what do you mean? – touhami Sep 30 '15 at 18:56
  • Well having a class that only compiles in the summer doesn't distinguish between summer 2015 and summer 2012 for example. – Alan Munn Oct 1 '15 at 13:21
  • @AlanMunn well, this is just example, I tnink you can complete it if you like the idea. – touhami Oct 1 '15 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.